使用在其他端口/主机上运行的后端测试聚合物项目

时间:2017-05-23 11:48:20

标签: ajax rest polymer polymer-2.x

我将建造和聚合物项目,这将是一个restapi的前端。

使用$ polymer serve在本地投放前端,这会启动http://127.0.0.1:8081上的服务器

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

我想用iron-ajax

执行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.

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

0 个答案:

没有答案
相关问题