9
*.api 没有引入 jwt
service ***-api { // code }
nginx 配置 [测试]
location /v3/ { add_header 'Access-Control-Allow-Origin' *; add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,PATCH,OPTIONS'; if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' *; add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,PATCH,OPTIONS'; return 200; }
rewrite ^/v3/(.*)$ /$1 break;
proxy_pass http://localhost:20103;
}
> nginx 配置[部署]
location /v3/ {
if ($request_method = 'OPTIONS') {
add_header Cache-Control private;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Max-Age' 86400;
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Token,DNT,Content-Type,Cache-Control,User-Agent,Keep-Alive,Authorization,authorization,beid,ptyid';
return 204;
}
add_header 'Access-Control-Allow-Origin' *;
add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,PATCH,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,token';
rewrite ^/v3/(.*)$ /$1 break;
proxy_pass http://localhost:20103;
}
> 接口请求请参考以下代码
<!DOCTYPE html>
#### 我的问题如下:
+ 我的api并没有引入jwt,理论上应该不会对header进行校验(自己瞎猜的),但使用header参数,会导致 CORS错误,如何优雅处理。
+ 如果nginx不进行header处理,有什么办法能够避免这个问题?
+ 测试接口: https://www.cakioe.com/v3/