我有下面的代碼,而path
真的很讓人困惑。 restify的api指南沒有太多解釋。restify路徑路徑含義
const restify = require('restify');
const app = restify.createServer();
app.get(/\/path\/.*/, function(req,res,next){
console.log('regexp');
return next(); // suppose to pass control to next handler, but nothing happended.
})
// it seems that '/path/:name' has the same meaning of /\/path\/.*/. Did I miss something?
app.get('/path/:name', function(req,res,next){
console.log('colon')
return next();// still not pass control to next handler
})
// those two works as expected.
app.get('/path/first', function(req,res,next){
res.end('first');
})
app.get('/path/second', function(req,res,next){
res.end('second');
})
app.listen(80, function() {
console.log('Server is running');
});
那麼有人可以向我解釋這些路徑的確切含義嗎?我怎樣才能使next()
工作?
假設我發送了一個請求,比如說'/ path/first'。我不想通過'/ \/path \ /.*/',''/ path /:name''和''/ path/first''來處理。我認爲next()會以這種方式工作,但實際上,只有'/ \/path \ /.*/'處理程序會被執行。 – agsonoo
它將使用它找到的第一個匹配項。就我所知,下一步()不能以這種方式工作。 – hudsond7