From 3b15fe9024a65e2756efa4e575098865b4b178cc Mon Sep 17 00:00:00 2001 From: binaryify Date: Sat, 12 Sep 2020 10:23:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index 02fe7c2..d78e978 100644 --- a/app.js +++ b/app.js @@ -38,15 +38,14 @@ app.use((req, res, next) => { // cookie parser app.use((req, res, next) => { - req.cookies = {}(req.headers.cookie || '') - .split(/\s*;\s*/) - .forEach((pair) => { - let crack = pair.indexOf('=') - if (crack < 1 || crack == pair.length - 1) return - req.cookies[ - decodeURIComponent(pair.slice(0, crack)).trim() - ] = decodeURIComponent(pair.slice(crack + 1)).trim() - }) + req.cookies = {} + ;(req.headers.cookie || '').split(/\s*;\s*/).forEach((pair) => { + let crack = pair.indexOf('=') + if (crack < 1 || crack == pair.length - 1) return + req.cookies[ + decodeURIComponent(pair.slice(0, crack)).trim() + ] = decodeURIComponent(pair.slice(crack + 1)).trim() + }) next() }) -- GitLab