Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a header in middleware node.js express framework

I have a middleware doing some auth. In this auth-method I need to set a response header.

server.get('/api/users, auth(), getUsers);

My authmethod:

module.exports = (isProduction) => {
  return function(req, res, next){
     ...

     next();

  }
}

How do I attach a header in this auth function?

like image 398
Joe Avatar asked Jan 25 '17 08:01

Joe


1 Answers

I assume you are using express.js. In express, there is a set function (documentation here. You can use it like this

res.set('<header name>', '<header value>')

before calling next()

like image 129
ThomasThiebaud Avatar answered Nov 09 '22 13:11

ThomasThiebaud