learning express.Router()

code:

const express = require('express');
const app = express();
var router = express.Router(); var cookieParser = require('cookie-parser'); app.use(cookieParser());
router.use(function (req, res, next) {
//if (!req.headers['x-auth']) return next('router');
//next();
}) router.get('/', function(req, res){
res.send('hello, user!');
}); app.use('/admin', router, function (req, res) {
res.sendStatus();
}); // app.use(function(err, req, res, next){
// console.error(err.stack);
// res.status(500).send('something broke');
// });
app.listen();

result:

learning express step(十一)的更多相关文章

  1. learning express step(十四)

    learning express error handle code: const express = require('express'); const app = express(); const ...

  2. learning express step(十三)

    learning express error handle code: const express = require('express'); const app = express(); app.g ...

  3. learning express step(十二)

    learning express view engine function const express = require('express'); const app = express(); app ...

  4. learning express step(五)

    learning  express  middleware var express = require('express'); var app = express(); var myLogger = ...

  5. learning express step(四)

    learning express route function const express = require('express'); const app = express(); app.get(' ...

  6. learning express step(九)

    router-level middleware works in the same way as application-level middleware, except it is bound to ...

  7. learning express step(八)

    To skip the rest of the middleware functions from a router middleware stack, call next('route') to p ...

  8. learning express step(七)

    Route handlers enable you to define multiple routes for a path. The example below defines two routes ...

  9. learning express step(六)

    code: use application middleware var express = require('express'); var app = express(); app.use(func ...

随机推荐

  1. Kafka集群安装及prometheus监控

    前提 zookeeper安装参考:https://www.cnblogs.com/JustinLau/p/11372782.html 其他安装参考:https://www.cnblogs.com/lu ...

  2. 怎样理解script标签的defer属性和async属性

    如果script标签是引用的外部js文件, 那就会有一个下载js文件这一过程, 为了不因为这个下载过程而阻塞页面解析与渲染, 我们需要一种机制来解决这一问题, 方法之一就是使用 defer和async ...

  3. K最近邻算法项目实战

    这里我们用酒的分类来进行实战练习 下面来代码 1.把酒的数据集载入到项目中 from sklearn.datasets import load_wine #从sklearn的datasets模块载入数 ...

  4. opencv 加载pb

    1.错误1         Tensor's data type is not supported the type of Mul  is DF_Float 2.  错误2 type == " ...

  5. SIP:100rel 扩展

    SIP:100rel 扩展 100rel扩展即是对中间状态响应的确认(即1xx的响应码).原先在sip里,只有针对invite请求的200ok响应才会有ack,那么当中间状态响应携带重要的会话参数信息 ...

  6. 私服nexus的权限问题,带admin和带view的区别

    admin和view的区别只找到了这个解释: https://blog.csdn.net/tian_111222333/article/details/100159983 最终得出答案,我只需要给他们 ...

  7. Django 配置JWT验证

    1.setting.py配置 REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_jwt.authentica ...

  8. Unity 宽度适配 NGUI

    这是很久之前写的一篇Note,现在移到Blog上来,可能有些参数,NGUI插件等等不和现在版本相同.不过大概的思路应该不会错. ps: 可能有部分內容是摘抄自其他作者,没办法考证了,如有请务必联系我. ...

  9. wepy全局拦截器

    wepy有支持全局拦截器,但是请求需要使用wepy.request().then(): 在app.wpy文件中配置以下内容,与data同级 constructor(){ super(); this.u ...

  10. JS基础 sessionStorage

    html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage. sessionStorage用于本地存储一个会话(session)中的数据,这些数据只 ...