-
Notifications
You must be signed in to change notification settings - Fork 800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access Control Allow Origin? #56
Comments
Does hot reload actually fail, or does it just output this message? |
Hm, the issue went away by itself after a reload. |
@ronag i've seen this as well - maybe is your server restarting itself (nodemon)? |
I also have this
|
This patch to |
Let's leave this open for posterity. |
I'm seeing the same issue when serving pages from node on 8888 and using the webpack dev server on 8080: |
@jbasdf add cors middleware to your webpack-dev-server |
Thanks @Dakuan, I ended up setting the headers when I start the server. Here's the code: var webpackDevServer = require('webpack-dev-server');
new webpackDevServer(webpack(webpackConfig), {
publicPath: "http://localhost:8080/build",
hot: true,
headers: { "Access-Control-Allow-Origin": "*" }
}).listen(settings.ports.hotPort, 'localhost', function(err, result){
if(err){
console.PluginError(err);
}
console.log('Webpack hot load server listening on port ' + settings.ports.hotPort);
}); |
CORS should not need to be enabled locally. If you want to access the dev server from another device in your local network, have your web servers run on your devices local IP instead if localhost. You can do this with webpack-dev-server by passing the |
I serve the page using node.js and the assets via the webpack-dev-server. They run on different ports so CORS has to be enabled or the browser will give you same origin errors. |
Ports do not matter, the domain does. As long as your servers are running on an internal IP other than localhost, CORS is not needed when accessing server resources from another device in the network. |
That was my assumption, but the version of Chrome I'm using wouldn't allow the socket connect until I added Access-Control-Allow-Origin": "*". |
I have not been using Chrome, but I just went and tested in Chrome v40.0.2214.115 m, and everything works as expected. |
This is on Troubleshooting page now, so closing. |
Thank @jbasdf ! Was having the same issue on Chrome 43 |
I'm having this issue by the way, and I've set the headers in the config. |
Oh, I'm not having this issue anymore: my port number in the corresponding webpack entry point |
@halt-hammerzeit Can you send a PR to Troubleshooting doc describing how you fixed the problem? Others may have the same issue. |
@gaearon Ok, here's how it was: webpack.config.js
And the variable |
@troutowicz ports do matter. According to MDN, "Two pages have the same origin if the protocol, port (if one is specified), and host are the same for both pages." An example shows that a request to a different port fails the same-origin policy. |
@jedwards1211 Strange. When I was working with this project I never had CORS issues when using private ip-ranges. |
I'm having this issue with webpack-dev-server 2.4.2 and react-hot-loader 3.0.0-beta-6. Adding { 'Access-Control-Allow-Origin': '*' } did not work |
@troutowicz that is strange. I have no idea if all browsers enforce CORS for |
Also running into the same issue as @hugotox with v2. |
@hugotox in your webpack config, try adding this:
|
@michaelBenin thanks a lot that fixed it! |
great that everyone is showing how to do it with the devServer, but what about the production server? where/how do i do that? where/how do i add this: |
That's something configured in the cdn or web server serving the file. What are you using? |
Try adding this: (where app = express() ) It worked for me. Add it near the top of the file after initializing express and before all of the webpack initialization code. |
You guys are the boss! Thanks for |
What is might be the problem here? Do I need to set some setting on the dev server for this to work?
The text was updated successfully, but these errors were encountered: