fix: 解决后端服务跨域的问题
All checks were successful
Web UI CI/CD / build-and-deploy (push) Successful in 3m23s
All checks were successful
Web UI CI/CD / build-and-deploy (push) Successful in 3m23s
This commit is contained in:
@@ -1,20 +1,19 @@
|
||||
VITE_BASE=/
|
||||
|
||||
# 请求路径
|
||||
VITE_BASE_URL=http://172.17.16.14:48080
|
||||
VITE_BASE_URL=/admin-api
|
||||
# 接口地址
|
||||
VITE_GLOB_API_URL=http://172.17.16.14:48080/admin-api
|
||||
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务
|
||||
VITE_GLOB_API_URL=/admin-api
|
||||
# 文件上传类型:server - 后端上传<EFBFBD><EFBFBD>?client - 前端直连上传,仅支持S3服务
|
||||
VITE_UPLOAD_TYPE=server
|
||||
|
||||
# 是否开启压缩,可以设置为 none, brotli, gzip
|
||||
# 是否开启压缩,可以设置<EFBFBD><EFBFBD>?none, brotli, gzip
|
||||
VITE_COMPRESS=none
|
||||
|
||||
# 是否开启 PWA
|
||||
# 是否开<EFBFBD><EFBFBD>?PWA
|
||||
VITE_PWA=false
|
||||
|
||||
# vue-router 的模式
|
||||
VITE_ROUTER_HISTORY=hash
|
||||
# vue-router 的模<EFBFBD><EFBFBD>?VITE_ROUTER_HISTORY=hash
|
||||
|
||||
# 是否注入全局loading
|
||||
VITE_INJECT_APP_LOADING=true
|
||||
|
||||
@@ -13,6 +13,27 @@ server {
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# API 反向代理到后端服务
|
||||
# 如果后端在 Docker 容器中,使用容器名:http://aiot-server:48080
|
||||
# 如果后端在宿主机上,使用内网地址:http://172.17.16.14:48080 或 http://172.17.0.1:48080
|
||||
location /admin-api {
|
||||
proxy_pass http://172.17.16.14:48080/admin-api;
|
||||
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 $scheme;
|
||||
|
||||
# 解决跨域问题
|
||||
add_header Access-Control-Allow-Origin * always;
|
||||
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS' always;
|
||||
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
||||
|
||||
# 处理 OPTIONS 预检请求
|
||||
if ($request_method = 'OPTIONS') {
|
||||
return 204;
|
||||
}
|
||||
}
|
||||
|
||||
# 解决 SPA 路由刷新 404 问题
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
|
||||
Reference in New Issue
Block a user