2

Is there a way to get the protocol (http|https) in Express?

JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
jwerre
  • 9,179
  • 9
  • 60
  • 69

1 Answers1

5

req.protocol:

app.get('/protocol', function (req, res) {
    res.send(req.protocol);
});

Though, you may also need to enable trust proxy for your application:

app.configure('production', function () {
    app.enable('trust proxy');
});
Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199