【发布时间】:2018-05-12 04:46:24
【问题描述】:
我在 Stack Overflow 上看到过其他类似的问题,但到目前为止,还没有什么对我有任何帮助。
我有一个 Angular 应用程序服务于 http://localhost:4200。 我有一个后端http://localhost:8080/myApp/
我正在尝试通过以下调用设置从前端到达后端:
public getPeople(): Observable<PeopleModel[]> {
return this.http
.post(API_URL + '/getPeopleDetails', {})
.map(response => {
const people = response.json();
console.log(people);
return partners.map((people) => new PeopleModel(people));
})
.catch(this.handleError);
}
API_URL 设置为http://localhost:8080/myApp
我的代理配置如下所示:
{
"/myApp/*": {
"target": "http://localhost:8080/myApp",
"secure": false,
"changeOrigin": true,
"logLevel": "debug",
"pathRewrite" : {"^/myApp" : "http://localhost:8080/myApp"}
}
}
我的 package.json 有以下内容:
"start": "ng serve --proxy-conf proxy.conf.json",
我在尝试运行应用程序时收到的错误是 CORS 错误和 403。
Failed to load http://localhost:8080/myApp/getPeopleDetails: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 403.
如果有任何帮助,我将不胜感激。谢谢!
【问题讨论】:
-
你的“后端”是什么?
-
定义了多个端点的 Spring Boot 应用程序