NodeJS Express框架中处理404页面一个方式
在用Express的时候,路由是我最困惑的事之一。知道用app.get('*')可以处理所有页面,但这样除了自定义的其他路由外,静态文件是被忽略的。最近在写一个小工具的时候,找到了一个解决方案:
varexpress=require('express'),
router=require('./routes');
varapp=module.exports=express.createServer();
//Configuration app.configure(function(){ //... //别把顺序写反了 app.use(express.static(__dirname+'/public')); app.use(app.router); });
//其他router... //404 app.get('*',function(req,res){ res.render('404.html',{ title:'NoFound' }) });
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短