express中中间件的概念
//第一个中间件 app.use(function(req,rep,next){ consloe.log(1) next() }) //第二个中间件 app.use(function(req,rep,next){ consloe.log(2) next() })//所有以/ab、开头的请求都会进入中间件 app.use("/ab",function(req,rep,next){ console.log(req.url) //如果请求是"/ab/a" 这里的url是 "/a" })app.get("/a",function(req,rep){ }) app.post("/a",function(req,rep){ })
业务应用
配置404中间件
配置错误处理中间件
Last updated