Node.js 快速jwt:除非使用摩卡/柴不符合条件

Node.js 快速jwt:除非使用摩卡/柴不符合条件,node.js,express,express-jwt,Node.js,Express,Express Jwt,我正在开发一个站点,使用meanstack和expressjwt来阻止对我站点的api调用的访问,除非用户经过身份验证。有些api调用我需要未登录的用户访问,即/api/login和/api/register。当我使用firebug访问端点时,一切似乎都按预期工作,它在正确的条件下阻塞,并在正确的条件下允许。我甚至收到了firebug下的令牌。但是,如果我使用mocha/chai进行测试,我会收到“401 unauthorized”错误,指示“未找到授权令牌”。我使用以下代码忽略选定的端点: a

我正在开发一个站点,使用meanstack和expressjwt来阻止对我站点的api调用的访问,除非用户经过身份验证。有些api调用我需要未登录的用户访问,即/api/login和/api/register。当我使用firebug访问端点时,一切似乎都按预期工作,它在正确的条件下阻塞,并在正确的条件下允许。我甚至收到了firebug下的令牌。但是,如果我使用mocha/chai进行测试,我会收到“401 unauthorized”错误,指示“未找到授权令牌”。我使用以下代码忽略选定的端点:

app.js:

let expressJwt = require('express-jwt')

app.use(expressJwt({secret: process.env.AUTH_KEY}).
unless({path: ['/api/login', '/api/register', /^\/api\/external\/.*/]}));
routes.js:

module.exports = function(app, mongoose){
    app.use("/api/register", require("./routes/registration")(mongoose));
    app.use("/api/external/games", require("./routes/games")(mongoose));
    app.use("/api/external/shopping", require("./routes/shopping")(mongoose));
}
routes/registration.js:

'use strict'

module.exports = function(){
    const express = require('express'); 
    const router = express.Router();
    const RegistrationFactory = require('../factories/RegistrationFactory');
    const registrationFactory = new RegistrationFactory();

    router.use(function(req, res, next) {
    next();
    });

    /* GET users listing. */
    router.post('/', function(req, res, next) {
        const registrationService = registrationFactory.create();
        registrationService.register(req.body, function(err, user){
            if (!err && user){
                console.log(err);
                res.sendStatus(200);
            } else {
                return next(err);
            }
        })
    });

    return router;
}
我想封锁除上述三条线路外的所有线路。有人能指出我做错了什么,因为我没有看到它吗?我是node.js的新手