-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Adding custom headers to "react-scripts start" #10210
Comments
Using the meta element is great for CSP, but if you want to experiment with Content-Security-Policy-Report-Only, you cannot use a meta tag. |
This is pretty annoying :( I need the ability to set "Cross-origin-Embedder-Policy" and "Cross-origin-Opener-Policy" in order to use sharedarraybuffer from web assembly. This means we can't use CRA and will have to eject/go elsewhere |
As a workaround, I've used the ability to configure the proxy manually (https://create-react-app.dev/docs/proxying-api-requests-in-development/#configuring-the-proxy-manually) to instead a custom middleware that adds headers. Specifically, I created a module.exports = function (app) {
app.use(function (req, res, next) {
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
next();
});
}; |
Thanks for this @mihaip! |
Where did you put this? |
@kudorgyozo it goes in |
It's not working for me, you just need to add that piece of code to "src/setupProxy.js"? |
@MatayoshiMariano you also need to install |
like this? but still not working,not work in react SPA application |
@nicky132 you can just install |
this is working on dev but not on production build |
@AmitShimon198 what service are you using for production deployments? |
can enyone suggest how to create condition if wasm set headers else just next()? i tried to log requests - they are all the same |
Hi @mykhailo-kabanenko , you always have to call next() to continue with your request, but only once. module.exports = function (app) {
app.use(function (req, res, next) {
if (condition) {
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
}
next();
});
}; Please tell me if I understood your question well. |
not running in static site |
Is your proposal related to a problem?
I would like to be able to set custom HTTP headers when using
npm start
, i.e.react-scripts start
.Currently our proxy provides CSP HTTP Headers.
During local development one might introduce CSP problems which only show up once a production build has been deployed.
The following would be helpful during development:
Describe the solution you'd like
Webpack provides devServer.headers which could be exposed in some way.
Describe alternatives you've considered
We could add a meta element to our public/index.html.
Additional context
#4861
The text was updated successfully, but these errors were encountered: