allocate js cookie in middleware, update res cookie distribution

This commit is contained in:
Nzix
2018-09-25 19:31:47 +08:00
parent f8660cdca6
commit 50adbfd804
6 changed files with 40 additions and 46 deletions

11
app.js
View File

@ -45,11 +45,20 @@ app.use(express.static(path.resolve(__dirname, 'public')))
app.use(function(req, res, next) {
const proxy = req.query.proxy
if (proxy) {
req.headers.cookie = req.headers.cookie + `__proxy__${proxy}`
req.headers.cookie += `__proxy__${proxy}`
}
next()
})
// 补全缺失的cookie
const { completeCookie } = require('./util/init')
app.use(function(req, res, next) {
let cookie = completeCookie(req.headers.cookie)
req.headers.cookie = cookie.map(x => x[0]).concat(req.headers.cookie || []).join('; ')
res.append('Set-Cookie', cookie.map(x => (x.concat('Path=/').join('; '))))
next()
})
// 因为这几个文件对外所注册的路由 和 其他文件对外注册的路由规则不一样, 所以专门写个MAP对这些文件做特殊处理
const UnusualRouteFileMap = {
// key 为文件名, value 为对外注册的路由