我有两条路线:app.use服务于静态文件。不同参数的ExpressJS路由
app.use('/test', earlyAccess(), express.static(path.join(__dirname, staticFolder)))
app.get("/test", callback);
app.get("/test/:id", callback);
// Here is the callback
var fileStream = fs.createReadStream(staticFolder + '/test.html');
fileStream.on('open', function() {
fileStream.pipe(res);
});
从浏览器中,如果我拨打localhost:80/test/1
- 工作正常。 但如果我打电话localhost:80/test
- 它会被重定向到主页面。在服务器控制台中,我收到了304条警告。
如何在expressjs中使用基于参数的路由?
304仅指示文档未被修改。 '/ test'中的回调是做什么的? –
加载HTML。 test /:id和/ test加载相同的html页面。 – user2325247
你可以提供回调函数吗?! –