从错误信息来看,这是一个典型的跨域(CORS)问题。错误显示访问 http://localhost:3000/api/match_summary 时被CORS策略阻止,因为 'Access-Control-Allow-Origin' header 的值 http://localhost:8080 与实际源 https://sp.ifballs.com 不匹配。
nginxserver { listen 80; server_name sp.ifballs.com; # 替换成你的域名 location /api { # 代理到后端服务 proxy_pass http://localhost:3000; # 添加跨域配置 add_header Access-Control-Allow-Origin $http_origin; add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; add_header Access-Control-Allow-Credentials 'true'; # 处理 OPTIONS 请求 if ($request_method = 'OPTIONS') { return 204; } } location / { root /path/to/your/dist; # 替换成你的dist目录路径 index index.html; try_files $uri $uri/ /index.html; } }
vue// 修改所有API请求路径 // 原来的: const response = await fetch('http://localhost:3000/api/match_summary'); // 改为: const response = await fetch('/api/match_summary');
bashnginx -s reload
提示
如果仍有问题,请检查:
本文作者:Kevin@灼华
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!