update frontend api and nginx config
This commit is contained in:
@@ -3,7 +3,8 @@ import axios from 'axios';
|
|||||||
const TOKEN_KEY = 'auth_token';
|
const TOKEN_KEY = 'auth_token';
|
||||||
|
|
||||||
const http = axios.create({
|
const http = axios.create({
|
||||||
baseURL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:33001',
|
// 🔥 核心修改
|
||||||
|
baseURL: '',
|
||||||
timeout: 15000,
|
timeout: 15000,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -25,7 +26,6 @@ http.interceptors.response.use(
|
|||||||
(error) => {
|
(error) => {
|
||||||
const status = error?.response?.status;
|
const status = error?.response?.status;
|
||||||
if (status === 401 || status === 403) {
|
if (status === 401 || status === 403) {
|
||||||
// Clear stored credentials and redirect to login
|
|
||||||
localStorage.removeItem(TOKEN_KEY);
|
localStorage.removeItem(TOKEN_KEY);
|
||||||
localStorage.removeItem('auth_user');
|
localStorage.removeItem('auth_user');
|
||||||
window.location.href = '/login';
|
window.location.href = '/login';
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import react from '@vitejs/plugin-react';
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
server: {
|
server: {
|
||||||
|
host: true,
|
||||||
port: 3000,
|
port: 3000,
|
||||||
host: '0.0.0.0', // 监听所有网络接口
|
host: '0.0.0.0', // 监听所有网络接口
|
||||||
proxy: {
|
proxy: {
|
||||||
@@ -17,5 +18,15 @@ export default defineConfig({
|
|||||||
clientPort: 80, // nginx监听80端口,外部代理将HTTPS 443转发到80
|
clientPort: 80, // nginx监听80端口,外部代理将HTTPS 443转发到80
|
||||||
protocol: 'ws', // WebSocket协议,nginx代理WebSocket
|
protocol: 'ws', // WebSocket协议,nginx代理WebSocket
|
||||||
},
|
},
|
||||||
|
|
||||||
|
allowedHosts: 'all',
|
||||||
|
|
||||||
|
hmr: {
|
||||||
|
host: 'performance-appraisal.excn.top',
|
||||||
|
protocol: 'wss',
|
||||||
|
clientPort: 443
|
||||||
|
},
|
||||||
|
|
||||||
|
// ❌ 直接删掉 proxy(推荐)
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
92
nginx.conf
92
nginx.conf
@@ -1,94 +1,34 @@
|
|||||||
# Nginx configuration for performance appraisal system
|
|
||||||
# This file will be mounted into nginx container
|
|
||||||
|
|
||||||
events {
|
|
||||||
worker_connections 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
http {
|
|
||||||
include mime.types;
|
|
||||||
default_type application/octet-stream;
|
|
||||||
|
|
||||||
# Logging
|
|
||||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
||||||
'$status $body_bytes_sent "$http_referer" '
|
|
||||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
|
||||||
access_log /var/log/nginx/access.log main;
|
|
||||||
error_log /var/log/nginx/error.log warn;
|
|
||||||
|
|
||||||
# Gzip compression
|
|
||||||
gzip on;
|
|
||||||
gzip_vary on;
|
|
||||||
gzip_min_length 1024;
|
|
||||||
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
|
|
||||||
|
|
||||||
# Real IP configuration for proxy (ESA HTTPS proxy)
|
|
||||||
real_ip_header X-Forwarded-For;
|
|
||||||
set_real_ip_from 0.0.0.0/0; # Trust all proxies (adjust if you know ESA proxy IPs)
|
|
||||||
|
|
||||||
# Server block for domain
|
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name performance-appraisal.excn.top;
|
server_name performance-appraisal.excn.top;
|
||||||
|
|
||||||
# Redirect to HTTPS if request came via HTTP (not from ESA proxy)
|
|
||||||
if ($http_x_forwarded_proto = "http") {
|
if ($http_x_forwarded_proto = "http") {
|
||||||
return 301 https://$server_name$request_uri;
|
return 301 https://$server_name$request_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Frontend React development server (via Docker network)
|
# 🔥 API(必须放前面 + ^~)
|
||||||
location / {
|
location ^~ /api/ {
|
||||||
proxy_pass http://frontend:3000;
|
|
||||||
|
rewrite ^/api/api/(.*)$ /api/$1 break;
|
||||||
|
|
||||||
|
proxy_pass http://backend:3001/;
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
|
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
|
||||||
|
|
||||||
# WebSocket support for hot reload (development)
|
add_header X-Debug-API "hit-api";
|
||||||
|
}
|
||||||
|
|
||||||
|
# 前端
|
||||||
|
location / {
|
||||||
|
proxy_pass http://frontend:3000;
|
||||||
|
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Backend API reverse proxy
|
|
||||||
location /api/ {
|
|
||||||
proxy_pass http://backend:3001/;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
|
|
||||||
|
|
||||||
# Increase timeout for long-running AI requests
|
|
||||||
proxy_read_timeout 120s;
|
|
||||||
proxy_connect_timeout 15s;
|
|
||||||
proxy_send_timeout 15s;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Static assets (if any)
|
|
||||||
location /assets/ {
|
|
||||||
proxy_pass http://frontend:3000/assets/;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
|
|
||||||
|
|
||||||
# Cache static assets
|
|
||||||
expires 30d;
|
|
||||||
add_header Cache-Control "public, immutable";
|
|
||||||
}
|
|
||||||
|
|
||||||
# Health check endpoint
|
|
||||||
location /health {
|
|
||||||
access_log off;
|
|
||||||
return 200 "healthy\n";
|
|
||||||
add_header Content-Type text/plain;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Optional: Redirect www to non-www
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name www.performance-appraisal.excn.top;
|
|
||||||
return 301 https://performance-appraisal.excn.top$request_uri;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user