[英]Angular-cli CORS settings
I have backend url http://docker-users:5500/users?all=true
which returns me list of users. 我有后端URL
http://docker-users:5500/users?all=true
,它返回了我的用户列表。 In angular-cli localhost url is: http://localhost:4200
. 在angular-cli localhost中,URL为:
http://localhost:4200
。 I have set proxy.config.json and add it to ng serve
. 我已经设置了proxy.config.json并将其添加到
ng serve
。 Problem is I still get 404 error when I am trying to reach. 问题是当我尝试到达时仍然出现404错误。 Where could be my mistake?
我的错误可能在哪里?
proxy.config.json: proxy.config.json:
{
"/api/*": {
"target": "http://docker-users:5500",
"secure": false,
"changeOrigin": true
}
}
service.ts 服务
const headers = new Headers({ 'Content-Type': 'application/json;'});
const params = new URLSearchParams();
params.append('all', true);
const options = new RequestOptions({ headers: headers, params: params });
const resp = this.http.get('/api/users', options)
...
Add pathRewrite
option: 添加
pathRewrite
选项:
{
"/api": {
"target": "http://docker-users:5500",
"secure": false,
"pathRewrite": {
"^/api": ""
},
"changeOrigin": true,
"logLevel": "debug"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.