【发布时间】:2017-01-23 20:57:09
【问题描述】:
我有一个简单的快速服务器文件。
我正在尝试让我的 app.get('*') 块中的任何代码执行。但是,当我放入 console.log 时,它不会显示在我的根目录中。它适用于我的其他路线,但绝不适用于“/”路线。作为参考,我正在本地开发,所以它不适用于http://localhost:8080/
const app = express();
const port = process.env.PORT ? process.env.PORT : 8181;
const dist = path.join(__dirname, 'dist');
app.get('*', (req, res, next) => {
console.log('Why wont you show on /')
});
app.use(express.static(dist));
//These two routes work...
app.get('/info', getInfo);
app.get('/infoDetail', getID);
app.listen(port, (error) => {
if (error) {
console.log(error); // eslint-disable-line no-console
}
console.info('Express is listening on port %s.', port); // eslint-disable-line no-console
});
dist文件夹已经编译好css、js和index.html
【问题讨论】:
-
使用
app.all('*', (req, res, next) => {是否有效?
标签: express