Angularjs 正在尝试使用grunt connect代理连接到laravel后端
我发现自己很难使用grunt connect proxy从运行在端口9000上的yeoman生成的angular应用程序调用运行在端口8000上的laravel后端。按照grunt connect代理github上的说明操作后,我在运行grunt Service时看到以下消息:Angularjs 正在尝试使用grunt connect代理连接到laravel后端,angularjs,laravel,gruntjs,grunt-connect,Angularjs,Laravel,Gruntjs,Grunt Connect,我发现自己很难使用grunt connect proxy从运行在端口9000上的yeoman生成的angular应用程序调用运行在端口8000上的laravel后端。按照grunt connect代理github上的说明操作后,我在运行grunt Service时看到以下消息: Running "configureProxies:server" (configureProxies) task Proxy created for: /api to localhost:8000 我在connect
Running "configureProxies:server" (configureProxies) task
Proxy created for: /api to localhost:8000
我在connect.Proxy中设置了我的代理,直接在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)
以下是包含我的完整GrunFile的要点链接:
我在这方面看到了不少帖子,但到目前为止,没有一篇对我有多大帮助。我还没有使用$resource,而是使用了$http.post(“/api”…..对我有效。我还使用了自述文件中完全相同的配置。我能够通过更改apache服务器的配置使其在0.0.0.0上运行,使用:php artisan-service--host 0.0.0。这让我相信这不是grunt任务的问题,而是与apache服务器通信的问题服务器。