使用express连接http
node_bin -const express = require("express");
// 创建http实例
const app = express();
app.use((req,res,next) => {
console.log('请求开始...', req.method,req.url);
next();
})
app.use((req,res,next) => {
req.cookie = {
userId: 'aaa111'
}
next()
})
app.use('/api', (req,res,next) => {
console.log('处理/api路由');
next();
})
app.get('/api', (req,res,next) => {
console.log('get处理/api路由');
next();
})
app.post('/api', (req,res,next) => {
console.log('post处理/api路由');
next();
});
app.use((req, res, next) => {
console.log('处理 404')
res.json({
errno: -1,
msg: '404 not fount'
})
})
app.listen(3000, () => {
console.log('server is running on port 3000')
})
特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。
上一篇: 前端面试每日 3+1 —— 第984天
下一篇: HTML5中的自定义属性总结