bluehalo / mean2-starter

Other
4 stars 0 forks source link

Adding access-control headers to the webpackDevServer configuration #129

Closed pblair12 closed 7 years ago

pblair12 commented 7 years ago

I was seeing this error in both Chrome and Firefox

Access to Font at 'http://localhost:9000/dev/af7ae505a9eed503f8b8e6982036873e.woff2' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

Because of that error I was not able to view the font awesome icons in mean2 starter.

The fix was to add headers to the webpackDevServer configuration:

{ 'Access-Control-Allow-Origin': `${config.app.url.protocol}://${config.app.url.host}:${config.app.url.port}`, 'Access-Control-Allow-Credentials': 'true' }

reblace commented 7 years ago

I think you can simplify the change to just:

headers: { 'Access-Control-Allow-Origin': '*' }

Since this is only used in dev mode, it's ok imo to allow any cross origin request.

pblair12 commented 7 years ago

@reblace good idea! done