【发布时间】:2015-02-18 20:26:57
【问题描述】:
我正在开发一个 Angular / Laravel 项目,但我在配置 Grunt 代理时遇到了麻烦正确地,我已经遵循了几个教程并进行了一些研究以解决这个问题,但我没有成功。
问题是配置的代理没有按照应有的方式重定向到主机,我设置将请求从 /localhost:9000/api 转发到 /localhost:8000/api ,但是当我发出请求时:
推荐网址:http://localhost:9000/api/whataver
请求网址:http://localhost:9000/api/whatever
正在向同一主机发出请求,因此请求没有正确代理,有什么建议吗?
这是我的 grunt 文件的一部分:
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: '127.0.0.1',
livereload: 35729
},
proxies: [
{
context: '/api',
host: '127.0.0.1',
port: 8000,
https: false,
changeOrigin: false
}
],
livereload: {
options: {
open: true,
base: [
'.tmp',
'<%= yeoman.app %>'
],
middleware: function (connect,options) {
var middlewares = [];
if (!Array.isArray(options.base)) {
options.base = [options.base];
}
// Set up the proxy
middlewares.push(require('grunt-connect-proxy/lib/utils').proxyRequest);
//server static files
middlewares.push(
modRewrite(['^[^\\.]*$ /index.html [L]']),
connect.static('.tmp'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect.static(appConfig.app)
);
return middlewares;
}
}
}
感谢您的帮助,谢谢!
【问题讨论】:
-
嘿,赫克托,我在这里遇到了完全相同的问题,您找到解决方案了吗?谢谢!
-
您好 danboh,是的,我找到了解决方案...让我知道您的做法,也许我可以帮助您...不过我会发布解决方案我发现我的实际配置。问候
标签: angularjs gruntjs yeoman yeoman-generator-angular