我正在使用swagger-express-mw构建Node / Express / Swagger应用,并且已经通过步骤here设置了Bearer身份验证
可以找到我的身份验证助手here,与本案例中的教程唯一不同的是,在我的app.js
文件中,我有以下内容:
var config = {
appRoot: __dirname, // required config
swaggerSecurityHandlers: {
Bearer: auth.verifyToken
}
};
代替此:
app.use(middleware.swaggerSecurity({
//manage token function in the 'auth' module
Bearer: auth.verifyToken
}));
当我使用带有授权标头的Postman进行请求时,一切正常,但是,如果我省略标头(以模拟未授权的请求),则会出现此错误:
Error: Can't set headers after they are sent.
at validateHeader (_http_outgoing.js:491:11)
at ServerResponse.setHeader (_http_outgoing.js:498:3)
at /Library/WebServer/Documents/node/checkout.harperconcierge.com/node_modules/swagger-node-runner/lib/connect_middleware.js:62:24
at /Library/WebServer/Documents/node/checkout.harperconcierge.com/node_modules/lodash/index.js:3073:15
at baseForOwn (/Library/WebServer/Documents/node/checkout.harperconcierge.com/node_modules/lodash/index.js:2046:14)
at /Library/WebServer/Documents/node/checkout.harperconcierge.com/node_modules/lodash/index.js:3043:18
at Function.<anonymous> (/Library/WebServer/Documents/node/checkout.harperconcierge.com/node_modules/lodash/index.js:3346:13)
at Runner.finishConnect (/Library/WebServer/Documents/node/checkout.harperconcierge.com/node_modules/swagger-node-runner/lib/connect_middleware.js:61:15)
关于如何解决此问题的任何想法?