2

我发现自己很难使用 grunt-connect-proxy 从运行在端口 9000 上的 yeoman 生成的 angular 应用程序调用在端口 8000 上运行的 laravel 后端。按照 grunt-connect-proxy github 上的说明进行操作后,我看到了运行 grunt serve 时出现以下消息:

Running "configureProxies:server" (configureProxies) task
Proxy created for: /api to localhost:8000

我在 connect.proxies 中直接在 connect.options 之后设置了我的代理:

proxies: [{
  context: '/api', // the context of the data service
   host: 'localhost', // wherever the data service is running
   port: 8000 // the port that the data service is running on
}],

然后在我的控制器中尝试调用 api 来测试我的代理:

var Proxy = $resource('/api/v1/purchase');
Proxy.get(function(test){
  console.log(test);
});

在我的控制台中的结果是一个 500 错误,表明调用仍然是对端口 9000 而不是 8000:

http://localhost:9000/api/v1/purchase 500 (Internal Server Error) 

这是包含我完整 gruntfile 的要点的链接: https ://gist.github.com/JohnBueno/7d48027f739cc91e0b79

我已经看过很多关于此的帖子,但到目前为止,没有一个对我有太大帮助。

4

0 回答 0