[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
With Nest 6, what is the proper way to disable the x-powered-by: Express
header? It seems like disable(...)
has been removed.
I don't see any relevant information in the v6 documentation about this particular change.
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.disable('x-powered-by'); // no longer works
app.use(nocache());
await app.listen(1338);
}
bootstrap();
Nest version: 6.0.1
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.disable('x-powered-by');
NestExpressApplication
is imported from @nestjs/platform-express
package.
see https://docs.nestjs.com/first-steps#platform
Thanks. I think the migration guide could use this information as well.
@kamilmysliwiec interestingly when I tried your suggestion with nest 6.2.4, I am unable to properly remove x-powered-by: Express
header. when I add app.disable('x-powered-by');
and check the headers again, the header is changed to capitalised word version X-Powered-By
.
I have tried adding both casings as:
app.disable('x-powered-by');
app.disable('X-Powered-By');
but api is still responding with X-Powered-By: Express
.
The only thing that worked is overwriting it with custom string.
app.use(function(req, res, next) {
res.header('x-powered-by', 'Blood, sweat, and tears.');
next();
});
@sajidali you can also create an express instance and configure it as you want, and then pass it back to the NestFactory 馃槂
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Thanks. I think the migration guide could use this information as well.