1 Star 0 Fork 1

zhangchengtest/expressStudy

forked from echozhangzy/expressStudy 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
echozhangzy 提交于 2016-05-16 15:47 . app.mountpath 挂接
/*
* @Author: ZhangZheyi
* @Date: 2016-05-16 10:45:40
* @Last Modified by: ZhangZheyi
* @Last Modified time: 2016-05-16 14:32:16
*/
'use strict';
var express = require('express');
var app = express();
// app.get('/', function(req, res) {
// res.send('Hello World!');
// });
//使用一个回调函数处理路由:
// app.get('/example/a', function (req, res) {
// res.send('Hello from A!');
// });
//使用多个回调函数处理路由(记得指定 next 对象):
// app.get('/example/b', function (req, res, next) {
// console.log('response will be sent by the next function ... 多个回调函数处理路由在命令控制面板输出');
// next();
// }, function (req, res) {
// res.send('Hello from B!');
// });
//使用回调函数数组处理路由:
// var cb0 = function (req, res, next) {
// console.log('CB0');
// next();
// }
// var cb1 = function (req, res, next) {
// console.log('CB1');
// next();
// }
// var cb2 = function (req, res) {
// res.send('Hello from C!');
// }
// app.get('/example/c', [cb0, cb1, cb2]);
//混合使用函数和函数数组处理路由:
var cb0 = function (req, res, next) {
console.log('CB0');
next();
}
var cb1 = function (req, res, next) {
console.log('CB1');
next();
}
app.get('/example/d', [cb0, cb1], function (req, res, next) {
console.log('response will be sent by the next function ...');
next();
}, function (req, res) {
res.send('Hello from D!');
});
var server = app.listen(3000, function() {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangchengtest/expressStudy.git
git@gitee.com:zhangchengtest/expressStudy.git
zhangchengtest
expressStudy
expressStudy
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385