我在middleware.js
const config = require('config');
const basicAuth = require('express-basic-auth');
const express = require ('express');
const app = express();
const token = config.get('restServerToken');
app.use(basicAuth({ authorizer: myAuthorizer }))
function myAuthorizer(username) {
const userMatches = basicAuth.safeCompare(username, [token])
return userMatches
}
module.exports.myAuthorizer = myAuthorizer;
当我尝试通过
调用sever.js
中的方法时
const middleware = require('./middleware/middleware')
middleware.myAuthorizer();
我收到一条错误消息:““ string”参数必须是string,Buffer或ArrayBuffer类型之一。接收到的类型未定义“
当我在同一模块中使用此Auth时,一切正常。 显然我在模块导出过程中做错了什么,有人可以指出我做错了吗?