Closed yfr closed 11 years ago
Can you elaborate more on your scenario? I'm haven't run into a scenario where the referer header gets in the way of CORS requests.
This is meant to be a development proxy, so i'm not sure if adding more controls over header is ideal. Will let people vote this up or down as needed.
Here's what I recommend.... you can wrap the proxyRequest function setup as grunt connect middleware with your own function to override the header prior to passing into the proxying:
livereload: {
options: {
middleware: function (connect) {
return [
function(req, res, options) {
req.headers.referer = '';
proxySnippet(req, res, options);
},
lrSnippet,
mountFolder(connect, '.tmp'),
mountFolder(connect, 'app')
];
}
}
}
Thank you! this works nicely.
my Probelm:
I have a grunt server running on localhost:9000 with my app and one rails server on a dev domain (like rails-server.dev) on my local mashine. I had to set the referer in the request to an emtpy string (or delete it) to get the connection to work. Even though i set the changeOrigin to true. This is only if i do a request from the webapp.
If i call the api directly (like localhost:9000/api) the proxy redirects and i get my results back. Without changing the referer.
this i my config:
{
context: '/api',
host: 'rails-server.dev',
rewrite: {
'^/api': ''
},
hmmm, i would hope the rails app would be able to handle referer headers better, but perhaps that is out of your control.
closing the issue as it's unblocked with the alternative middleware. people can vote on this if there is need to do this directly in the proxy.
Yeah. I think this is not happening very often. And your solution is quite easy and clean.
Thanks!
A possibility to change specific header would be nice. I ran into a problem where i had to remove the referer header to get a CORS request for dev running.
in utils.proxyRequest i added:
and changed config in the gruntfile accrodingly. Would be nice to change headers more generaly. Or i there a better solution?
what do you think?