0

我正在构建一个将成为restapi前端的聚合物项目。

使用它在本地提供前端服务会$ polymer serve启动服务器http://127.0.0.1:8081

我的后端也可以在本地运行$ python -m swagger_server并监听:http://127.0.0.1:8080

我想做ajax请求iron-ajax

  <iron-ajax auto id="ajax" url="http://localhost:8080/api/order" last-response="{{orders}}"></iron-ajax>

但不同的端口号使其成为跨域请求:

XMLHttpRequest cannot load http://localhost:8080/api/order. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access.

此外,这仅用于测试;在生产服务器上,跨域问题将通过为前端(on /)和后端(on /api)提供服务的网络服务器来解决。在部署之前,我将不得不删除所有http://127.0.0.1:8080并只留下路径/api/orders

4

0 回答 0