learning express step(十一)

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(401);
});

// app.use(function(err, req, res, next){
//     console.error(err.stack);
//     res.status(500).send('something broke');
// });
app.listen(3000);

result:

 

posted @ 2019-06-13 10:55  嵌入式实操  阅读(98)  评论(0编辑  收藏  举报