Basic HTTP authentication with Node and Express 4

后端 未结 9 2093
萌比男神i
萌比男神i 2020-11-29 15:48

It looks like implementing basic HTTP authentication with Express v3 was trivial:

app.use(express.basicAuth(\'username\', \'password\'));

V

9条回答
  •  天涯浪人
    2020-11-29 16:54

    A lot of the middleware was pulled out of the Express core in v4, and put into separate modules. The basic auth module is here: https://github.com/expressjs/basic-auth-connect

    Your example would just need to change to this:

    var basicAuth = require('basic-auth-connect');
    app.use(basicAuth('username', 'password'));
    

提交回复
热议问题