0
我想爲/ doc路徑起訴一箇中間件,以便它可以服務satic文件並具有基本身份驗證。如何在express nodejs中爲子路徑使用中間件路由器
但是,當我試圖讓/ doc我有一個無法得到/ doc錯誤。
有沒有人有任何想法?
var app = express();
app.use(bodyParser.urlencoded({ extended: true })); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()) ; // parse application/json
app.use(functio //app.use('/doc', express.static('./doc'));n(req, res, next) {
res.header("X-powered-by", "NodeJs");
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,Authorization");
next();
});
app.use(function(req, res, next) {
console.log(' - ',req.originalUrl);
next();
});
var router = express.Router();
router.use(express.basicAuth('testUser', 'testPass'));
router.get('/doc', function(req, res, next) {
console.log("inside doc");
express.static('./doc');
next();
});
app.use('/conf',require('./v1/data_config'));
感謝,並認爲
你有'app.use('/',路由器);'在該文件的末尾? – tcooc