I have a route.js which looks like this:
module.exports = function(app) {
app.get('/tip', function(req, res) {
res.render("tip");
});
app.get('/article', function(req, res) {
res.render("article");
});
app.get('/article1', function(req, res) {
res.render("article1");
});
app.get('/article2', function(req, res) {
res.render("article2");
});
app.get('/article3', function(req, res) {
res.render("article3");
});
app.get('/modules/:name', function(req, res) {
var name = req.params.name;
res.render('modules/' + name);
});
app.get('/modules/esaver/:name', function(req, res) {
var name = req.params.name;
res.render('modules/esaver/' + name);
});
};
Considering i have over 200 different routes to create, i would end up with stuff like 'article1', 'article2' etc
and my app.js is like:
var express = require('express')
,http = require('http')
,fs = require('fs')
,path = require('path');
var app = express();
html_templates = __dirname + '/html_templates';
app.set('views', html_templates + '/views');
app.set('view engine', 'jade');
app.use('/Core', express.static(__dirname + '/Core'));
app.listen(3000, function () {
console.log("express has started on port 3000");
});
require('./html_templates/controller/routes.js')(app);
Is there any dynamic way to create this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…