1.基本的有明显get.post的方法。
var router = express.Router();
router.post(‘/signout‘, sign.signout); // 登出
router.get(‘/signin‘, sign.showLogin); // 进入登录页面
router.post(‘/signin‘, sign.login); // 登录校验
router.get(‘/active_account‘, sign.activeAccount); //帐号激活
2.基本的
var app = express();
/*路由规划*/
app.get(‘/‘, routes.index);
app.get("/u/:user",routes.user); //用户的主页
app.post(‘/post‘,routes.post); //发表信息
app.get(‘/reg‘,routes.reg); //用户注册
app.post(‘/reg‘,routes.doReg);
app.get(‘/login‘,routes.login);//用户登录
app.post(‘/login‘,routes.doLogin);
app.get(‘/logout‘,routes.logout);//用户退出
http.createServer(app).listen(app.get(‘port‘), function(){
console.log("Express server listening on port " + app.get(‘port‘));
});
3.
var app = express();
app.route(‘/‘).get(check_login_cmd(‘html‘), index_cmd);app.route(‘/login‘).get(check_logout_cmd(‘html‘), login_cmd); //将/creative/下的请求都交给creative,即交给creative目录下的index.js//来处理,index.js控制二级路由,/user, /ratecard等以此类推app.use(‘/creative‘, creative);app.use(‘/user‘, user);app.use(‘/admin‘, admin);app.use(‘/ratecard‘, ratecard);app.use(‘/post‘, post);app.use(‘/spec‘, spec);app.use(‘/ueditor‘, ueditor);app.use(‘/openapi‘, openapi);在二级路由下面,公开get和post方法。
exports.get = function(req, res) {}
exports.post = function(req, res) {}
==========================================================================================================================================
把路由规划引入另一个js文件的做法。
1.app.use(‘/‘, webRouter);
然后在webRouter的js文件;
var router = express.Router();
router.post(‘/signout‘, sign.signout); // 登出
router.get(‘/signin‘, sign.showLogin); // 进入登录页面
router.post(‘/signin‘, sign.login); // 登录校验
router.get(‘/active_account‘, sign.activeAccount); //帐号激活
2.
var app = express();
controller.route(app);
app.route(‘/‘).get(check_login_cmd(‘html‘), index_cmd);
app.route(‘/login‘).get(check_logout_cmd(‘html‘), login_cmd);
//将/creative/下的请求都交给creative,即交给creative目录下的index.js
//来处理,index.js控制二级路由,/user, /ratecard等以此类推
app.use(‘/creative‘, creative);
app.use(‘/user‘, user);
app.use(‘/admin‘, admin);
==========================
模块的定义方式:
方法1.
function Person(){ var name; this.setName = function(theName){ name = theName; }; this.sayHello = function(){ console.log(‘Hello‘,name); }; } // exports.Person = Person; module.exports = Person;方法2. 比如 site.js模块exports.index = function (req, res, next) {}exports.sitemap = function (req, res, next) {}调用的方式:router.get(‘/‘, site.index);方法3:
exports.get = function(req, res) {}
exports.post = function(req, res){}这里调用的时候,不需要写方法名。==================================