我想为开发正确地配置grunt-connect代理,并避免出现CORS问题。
我有过
我安装了npm模块:
>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)我的Gruntfile.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',
(...)
]);
});该查询听起来不适合通过代理,因为它仍然可以在原始http://localhost:9000中看到。我收到以下错误:
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.尽管咕噜送达命令打印
Running "configureProxies:server" (configureProxies) task
Proxy created for: /mywebservice to localhost:8080它能让人联想到吗?
发布于 2016-04-26 10:10:20
https://stackoverflow.com/questions/36861616
复制相似问题