Create-react-app: Adding custom headers to "react-scripts start"

Created on 8 Aug 2018  路  6Comments  路  Source: facebook/create-react-app

This is really helpful when building apps that are meant to be embedded in and interact with another app. For example, the Invision Trello Power-Up used "npm eject" to be able to add the CORS headers that Trello Power-Ups are required to have.

I'm working on a solution in my own fork of react-scripts to avoid ejecting, as suggested in the Guide, but I wanted to get feedback on whether this is a feature that could be merged upstreamed and what it would need to look like.

Here's what I'm thinking: add a "headers" key to package.json, which contains an object of custom headers as passed to the Webpack dev server:

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

Other alternatives include adding a "cors": true or "cors": "*" option.

stale

Most helpful comment

Is there a reason CORS could not just be allowed for every origin in the dev server?

All 6 comments

If you just want to be able to use cors during dev, you can simply add a chrome extension for that. There are plenty to choose from.

https://chrome.google.com/webstore/search/cors?_category=extensions

Is there a reason CORS could not just be allowed for every origin in the dev server?

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs.

The cors extensions don't work for us locally, probably due to the same domain but different ports?

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oltsa picture oltsa  路  3Comments

stopachka picture stopachka  路  3Comments

Aranir picture Aranir  路  3Comments

ap13p picture ap13p  路  3Comments

jnachtigall picture jnachtigall  路  3Comments