Skip to content
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

Nest 6 and app.disable('x-powered-by') #1788

Closed
andreialecu opened this issue Mar 20, 2019 · 5 comments
Closed

Nest 6 and app.disable('x-powered-by') #1788

andreialecu opened this issue Mar 20, 2019 · 5 comments

Comments

@andreialecu
Copy link
Contributor

andreialecu commented Mar 20, 2019

I'm submitting a...


[ ] 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.

Current behavior

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.

What is the motivation / use case for changing the behavior?

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();

Environment


Nest version: 6.0.1
@kamilmysliwiec
Copy link
Member

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

@andreialecu
Copy link
Contributor Author

Thanks. I think the migration guide could use this information as well.

@sajidali
Copy link

sajidali commented May 31, 2019

@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();
  });

@shekohex
Copy link
Contributor

@sajidali you can also create an express instance and configure it as you want, and then pass it back to the NestFactory 😃

@lock
Copy link

lock bot commented Sep 23, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants