DEV Community

Discussion on: How to Hide the X-Powered-By Header in NestJS

Collapse
 
suzuki0430 profile image
Atsushi Suzuki

Thanks comment!

app.disable('x-powered-by') is an Express feature and is not applicable to Fastify adapters. If you are using Fastify, you will need to disable the X-Powered-By header using a different method.

I think it will look something like this.

import { FastifyAdapter } from '@nestjs/platform-fastify';

  const app = await NestFactory.create(AppModule, new FastifyAdapter());
  app.getHttpAdapter().getInstance().addHook('onSend', (request, reply, payload, done) => {
    reply.header('x-powered-by', '');
    done();
  });
Enter fullscreen mode Exit fullscreen mode