grunt connect proxy : proxy created 但我得到一个 404
grunt connect proxy : proxy created but i get a 404
我目前有一个使用 yeoman 配置的简单 angular 应用程序,我正在尝试的唯一自定义是使用 g运行t-connect-proxy。所以我按照说明修改了我的 G运行tfile :
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
module.exports = function (grunt) {
...
grunt.initConfig({
...
connect: {
...
server: {
proxies: [
{
context: '/api',
host: 'somevirtualhost',
port: 8080,
https: false,
changeOrigin: true
}
]
},
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
proxySnippet,
...
];
}
}
},
...
},
});
...
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
...
grunt.task.run([
...
'configureProxies:server',
...
]);
});
}
我在控制器中尝试了以下操作:
var Versions = $resource('/api/version/:versId', { versId: '@id' });
var version = Versions.get({ versId: 'Ultra' }, function () {
console.log('here I am');
});
当我 运行 g运行t 服务时,我可以看到代理已创建:
Running "configureProxies:server" (configureProxies) task
Proxy created for: /api to somevirtualhost:8080
但是在网页的控制台中我得到:
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:9000/api/version/Ultra
有什么想法吗?
我在这里找到了一些线索:https://github.com/drewzboto/grunt-connect-proxy/issues/69
我什么都不懂,但现在我在我的代理中添加了 headers 选项:
proxies: [
{
context: '/api',
host: 'somevirtualhost',
port: 8080,
https: false,
changeOrigin: true,
headers: {
'host': 'somevirtualhost'
},
}
]
它似乎有效
我目前有一个使用 yeoman 配置的简单 angular 应用程序,我正在尝试的唯一自定义是使用 g运行t-connect-proxy。所以我按照说明修改了我的 G运行tfile :
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
module.exports = function (grunt) {
...
grunt.initConfig({
...
connect: {
...
server: {
proxies: [
{
context: '/api',
host: 'somevirtualhost',
port: 8080,
https: false,
changeOrigin: true
}
]
},
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
proxySnippet,
...
];
}
}
},
...
},
});
...
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
...
grunt.task.run([
...
'configureProxies:server',
...
]);
});
}
我在控制器中尝试了以下操作:
var Versions = $resource('/api/version/:versId', { versId: '@id' });
var version = Versions.get({ versId: 'Ultra' }, function () {
console.log('here I am');
});
当我 运行 g运行t 服务时,我可以看到代理已创建:
Running "configureProxies:server" (configureProxies) task
Proxy created for: /api to somevirtualhost:8080
但是在网页的控制台中我得到:
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:9000/api/version/Ultra
有什么想法吗?
我在这里找到了一些线索:https://github.com/drewzboto/grunt-connect-proxy/issues/69 我什么都不懂,但现在我在我的代理中添加了 headers 选项:
proxies: [
{
context: '/api',
host: 'somevirtualhost',
port: 8080,
https: false,
changeOrigin: true,
headers: {
'host': 'somevirtualhost'
},
}
]
它似乎有效