我是比较简易的实现,改了下 express 的路由。
这样?
路由:
module.exports = function (app ) {
app.get ("/*", function (req, res, next ) {
toControl (req,res )
});
app.post ("/*", function (req, res, next ) {
toControl (req,res )
});
function toControl (req,res ){
var key = req.params['0'];
var control = require ('../controllers/' + key );
control (req,res );
}
}
controller :
var xxx = require ('../models/xxx.js');
module.exports = function (req,res ){
if (req.method == "GET"){
xxx.get ('xxxxx', function (err, xxx ) {
.........
res.render ( '<ejs path>', {
xxxx1 : 'xxxx',
xxxx2 : 'xxxx'
});
});
}else if (req.method == "POST"){
..........
}
};