Prevent Expressjs from creating a session when requests contain an authorization header?

前端 未结 4 861
野的像风
野的像风 2021-02-06 04:26

I have an API that can be called either using a browser where requests are transactional and have a session OR directly, eg. using curl, where requests are atomic. Browser reque

4条回答
  •  青春惊慌失措
    2021-02-06 05:19

    You can always just catch the response headers event and remove the 'set-cookie' header:

    app.use(function(req, res, next) {
      res.on('header', function () {
        if (req.headers.authorization) {
          delete res._headers['set-cookie'];
        }
      });
      next();
    });
    

    You can technically put this anywhere in your middleware chain.

提交回复
热议问题