app.set('x-powered-by', false) does not work on expressjs

Asked

Viewed 34 times

1

Hello, in my main code of my app, with the use of express, I’m trying to remove the "x-powered-by" header, and I’ve used so much

app.disable("x-powered-by")

how much

app.set("x-powered-by", false)

Besides, I’ve tried using the Helmet module .

But, no way comes into effect and the header continues to appear in the requests.

Follow the structure of my code:

const express        = require('express'),
      app            = express(),
      http           = require('http'),
      cors           = require('cors'),
      helmet         = require('helmet'),

app.set('x-powered-by', false);

...

app.use(cors());
app.use(helmet());

...

http
.createServer(app)
.listen(port, () => {
    console.log(`running in port ${port}`);
});
  • Have you tested with Helmet using hidePoweredBy and setTo: 'outra coisa'? Works well for me...

  • @Sergio, already, but still continues showing the "Express".

  • Samir, take a look here: https://ide.c9.io/sergiocrisostomo/sopt-218873, you can see the header?

  • @Sergio, you could be in charge of someone else who doesn’t need this signup?

  • Yes, this one you can see without signup here: https://sopt-218873-sergiocrisostomo.c9users.io/ Click on "open app"

  • @Sergio, the answer in the header has "x-powered-by: Renewable Energies, love and good music"

  • Exact :) You can switch to an empty string.

  • The currently running code is https://jsfiddle.net/waqt6z3L/

  • @Sergio, in his own way, locally it wasn’t working, but when going up to the host, it worked. You can put it as a response if you like. Thank you! :)

Show 4 more comments

1 answer

1


I use it like this with Elmet:

app.use(
    helmet({
        hidePoweredBy: {
            setTo: 'Renewable energies, love and good music'
        }
    })
);

And if you want you can pass an empty string on setTo.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.