配置的部分代码1.configuration.addAllowedOrigin("http://www.leyou.com");
2.server {
listen 80;
server_name http://www.leyou.com/;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://127.0.0.1:9002;
proxy_connect_timeout 600;
proxy_read_timeout 600;
}
}
3.spring:
application:
name: search-service
4. routes:
item-service: /item/** # 商品微服务的映射路径
search-service: /search/** # 路由到搜索微服务
报错的内容: Access to XMLHttpRequest at 'http://api.leyou.com/api/search/page' from origin 'http://127.0.0.1:9002' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
api.leyou.com/api/search/page:1 Failed to load resource: net::ERR_FAILED search.html:1 Access to XMLHttpRequest at 'http://api.leyou.com/api/auth/verify' from origin 'http://127.0.0.1:9002' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
域名怎么还弄了2个?
nginx配置的http://www.leyou.com/
把前端请求header中的Origin字段,赋值给addAllowedOrigin即可,不用写死