app.use inside a promise (bookshelf.js & express-basic-auth)
问题 Api.fetchAll({columns: ['username','password']}) .then(function(employee) { return employee.toJSON(); }) .then(function(employee){ app.use(basicAuth({ users: {employee} })); }); I need my middleware (app.use) to run before my node starts so it registers. It doesn't, so when I start my node, my basic auth never registers. I'm using express-basic-auth to do the basic authentication for my api, and bookshelf.js for retrieving the values in the database. 回答1: Okay so here is how I solved it.