我的应用 ( http://localhost:8099
) 正在执行一些 CORS 请求https://api.parse.com/
,我想代理到我的本地 apihttp://localhost:8077
以进行测试。这可以实现grunt-connect-proxy
吗?
这是我的 grunt-connect-proxy 配置,它不像我预期的那样工作。
connect: {
dev: {
options: {
port: 8099,
hostname: 'localhost',
base: 'build/',
livereload: false,
keepalive: true,
middleware: function (connect, options) {
var proxy = require('grunt-connect-proxy/lib/utils').proxyRequest;
return [
// Include the proxy first
proxy,
// Serve static files.
connect.static('build/')
];
}
}
},
proxies: [
{
context: ['api/'], //same domain api requests, proxy works fine!
host: 'localhost',
port: 8077
},
{
context: ['api.parse.com/'], //cors, proxy is not working
host: 'localhost',
port: 8077,
changeOrigin: true
}]
}
→ grunt serve
Proxy created for: api/ to localhost:8077
Proxy created for: api.parse.com/ to localhost:8077
因此,基本上代理适用于api/
请求(同一域),但对于 cors 对api.parse.com/
. 想法?