Using the same code in 3 diffrent sites that need diffrent headers

we have 3 sites in Netlify
all of them using the same repo
we added CSP headers to toml file
but we have a problem with the eval function
we don’t allow it in production and staging sites but need it in the storybook site

there is a way to control the headers dynamically by the sites

thanks, yotav

Hi, @yotav_masa, one solution is to modify the _header or netlify.toml file during the builds with a site specific build command.

For example you can have three different _header files like so:

  • site1-headers
  • site2-headers
  • site3-headers

Then for each site you can change the actual headers file as part of the build. For example, (using a build.publish setting of my-publish-directory) if the starting build.command is npm run build then the new build.command for site one would be:

cp site1-headers my-publish-directory/_headers && npm run build

This is only one of many options. For example, you might make the updating the _headers file part of the node build command itself instead of a separate command before it.

If there are other questions about this, please let us know.

1 Like

for now i just remove the toml in the specific site when i build