[英]how to check every request have the cookie in express js
我正在使用react和node構建一個原始應用程序,因此我需要檢查每個請求是否存在cookie。
app.all("*", (req,res) => {
// cookie doesn't exist redirect to login
if(cookieExist(req.headers.cookie)){
// how to pass to the next layer ? load the routes below code etc..
next();
}else{
res.redirect("/login")
}
})
const routes = require("./routes/route");
app.use(bodyParser.json());
app.use(cors());
app.use("/apiServices", apiRoutes)
我在這里所缺少的,得到未定義的next()。
定義next作為參數
app.all("*", (req,res, next) => {
// cookie doesn't exist redirect to login
if(cookieExist(req.headers.cookie)){
// how to pass to the next layer ? load the routes below code etc..
next();
}else{
res.redirect("/login")
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.