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. JVM 利用 VisualVM 对高并发项目进行性能分析(转)

    出处:  深入理解 Java 虚拟机-如何利用 VisualVM 对高并发项目进行性能分析 前面在学习JVM的知识的时候,一般都需要利用相关参数进行分析,而分析一般都需要用到一些分析的工具,因为一般使 ...

  2. echarts的基本使用以及如何使用官方实例的方法

    <!-- 为 ECharts 准备一个具备大小(宽高)的 DOM --> <div id="box" style="width: 600px;heigh ...

  3. vim编辑器中的替换(转)

    转1:https://www.cnblogs.com/david-wei0810/p/6385988.html 转2:https://blog.csdn.net/doubleface999/artic ...

  4. .NET Core中使用读取配置文件

    引入Nuget的两个类库 Microsoft.Extensions.Configuration Microsoft.Extensions.Configuration.Json 使用 var build ...

  5. gin框架实现一个简单的项目 ③

    承接:gin框架封装自己的路由 ② 对于一个项目来说,需要将各个功能模块分开,也就是所谓的三层模型,这里介绍一下个人的做法: contorller主要负责路由 model主要负责程序输入输出的数据 s ...

  6. MYSQL的B+Tree索引树高度如何计算

    前一段被问到一个平时没有关注到有关于MYSQL索引相关的问题点,被问到一个表有3000万记录,假如有一列占8位字节的字段,根据这一列建索引的话索引树的高度是多少? 这一问当时就被问蒙了,平时这也只关注 ...

  7. 你应该使用Python3里的这些新特性

    概述 由于Python2的官方维护期即将结束,越来越多的Python项目从Python2切换到了Python3.可是,在实际的工作中,我发现好多人都是在用Python2的思维去写Python3的代码, ...

  8. keepalived+lvs+usp安装实施文档

    操作系统平台:RedHat6.4  x86_64 软件:LVS+keepalived LVS+Keepalived 介绍 LVS LVS是Linux Virtual Server的简写,意即Linux ...

  9. Centos 升级至 OpenSSH 8 rpm包制作

    背景 安全部门扫描系统漏洞,OpenSSH 7.9出现漏洞,需升级到8. 使用 rpmbuild 将源码包编译为 rpm包. yum install rpm-build zlib-devel open ...

  10. 网页报警提示 This page includes a password or credit card input in a non-secure context. A warning has been added to the URL bar. For more information, see https://goo.gl/zmWq3m.

    This page includes a password or credit card input in a non-secure context. A warning has been added ...