Cors grunt连接代理配置不支持代理
我希望为开发正确配置grunt connect代理,避免出现CORS问题 我有Cors grunt连接代理配置不支持代理,cors,grunt-connect-proxy,Cors,Grunt Connect Proxy,我希望为开发正确配置grunt connect代理,避免出现CORS问题 我有 在本地tomcat上运行的REST Web服务 从运行在端口9000上的yeoman(v1.4.8)生成器创建的客户端应用程序。它连接到上述Web服务 我安装了npm模块: >npm install grunt-connect-proxy --save-dev grunt-connect-proxy@0.2.0 node_modules\grunt-connect-proxy ├── lodash@0.9.
- 在本地tomcat上运行的REST Web服务
- 从运行在端口9000上的yeoman(v1.4.8)生成器创建的客户端应用程序。它连接到上述Web服务李>
>npm install grunt-connect-proxy --save-dev
grunt-connect-proxy@0.2.0 node_modules\grunt-connect-proxy
├── lodash@0.9.2
└── http-proxy@1.11.3 (requires-port@0.0.1, eventemitter3@1.2.0)
我的GrunFile.js配置
require('jit-grunt')(grunt, {
(...)
configureProxies: "grunt-connect-proxy"
});
(...)
connect: {
options: {
port: 9000,
hostname: 'localhost',
livereload: 35729
},
proxies: [
{
context: ['/mywebservice'],
host: 'localhost',
port: 8080,
changeOrigin: true
}
],
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
require('grunt-connect-proxy/lib/utils').proxyRequest,
connect.static('.tmp'),
(...)
connect.static(appConfig.app)
];
}
}
},
(...)
}
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
(...)
grunt.task.run([
(...)
'configureProxies:server',
(...)
]);
});
查询听起来不适合通过代理,因为它仍然可以通过origin看到。我收到了以下错误:
XMLHttpRequest cannot load http://localhost:8080/xmlcompare-rs/xmlcompare. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
虽然grunt提供命令打印
Running "configureProxies:server" (configureProxies) task
Proxy created for: /mywebservice to localhost:8080
这个问题似乎来自您的REST服务服务器配置。 使用CORS筛选器可避免此异常 根据所使用的堆栈,实现可能会有所不同
我希望这能有所帮助谢谢你的回答。它与后端的CORS过滤器一起工作。然而,由于changeOrigin选项,我预计它将不再需要。无论如何,我从版本0.1.11(以及以后的版本)的发行说明中看到,节点0.10上的0.1.11修复Websocket支持-将http代理依赖项提升到1.1.4,删除了不受支持的http代理选项(拒绝未经授权、超时、changeOrigin)