We add security headers to NestJS requests.
We also serve static html files.
app.useGlobalInterceptors(new TransformHeadersInterceptor());
app.useStaticAssets(join(__dirname, "..", "public"), {
//index: false,
redirect: false
});
The headers are added to NestJS controller output but not to html files from public.
How would we do this? Do we need to go to Express level?
You have to set the headers to the static folder, this is the Express docs
one example could be this in the main.ts
app.useStaticAssets(`${__dirname}/public`,
{ setHeaders: (res, path, stat) => {
res.set('Access-Control-Allow-Origin', '*');
}});
you can add you headers in the setHeaders function Hope this help someone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With