我在做什么: 如果url中存在使用静态页面模板的数据库,如果没有,则显示特定的页面模板。似乎无法弄清楚,怎么过......node.js express routing db dependent
我app.js文件
app.get('*', function(req, res){
var currenturl = req.url;
console.log('URL IS: ' + my_path)
if (!!db.get(my_path))
{
//If it does exist in db
console.log('Does exist');
res.render('index', { thetitle: 'Express', title: db.get(currenturl).title, content: db.get(currenturl).content });
}else{
//If it doesn't exist in db
redirect to other sites
Like:
if you go to "/page" it will run this => app.get('/page', routes.index)
or "/users" will run => app.get('/users', routes.users)
}
});
这正是我期待的!谢谢! – dasmikko