mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 19:26:31 -05:00
Merge pull request #1468 from hedgedoc/session-cookie-status
[1.x] Exclude /metrics and /status routes from session initialization
This commit is contained in:
commit
64fd38b60c
2 changed files with 12 additions and 2 deletions
5
app.js
5
app.js
|
@ -27,6 +27,7 @@ const errors = require('./lib/errors')
|
||||||
const models = require('./lib/models')
|
const models = require('./lib/models')
|
||||||
const csp = require('./lib/csp')
|
const csp = require('./lib/csp')
|
||||||
const metrics = require('./lib/prometheus')
|
const metrics = require('./lib/prometheus')
|
||||||
|
const { useUnless } = require('./lib/utils')
|
||||||
|
|
||||||
const supportedLocalesList = Object.keys(require('./locales/_supported.json'))
|
const supportedLocalesList = Object.keys(require('./locales/_supported.json'))
|
||||||
|
|
||||||
|
@ -147,7 +148,7 @@ app.use('/uploads', express.static(path.resolve(__dirname, config.uploadsPath),
|
||||||
app.use('/default.md', express.static(path.resolve(__dirname, config.defaultNotePath), { maxAge: config.staticCacheTime }))
|
app.use('/default.md', express.static(path.resolve(__dirname, config.defaultNotePath), { maxAge: config.staticCacheTime }))
|
||||||
|
|
||||||
// session
|
// session
|
||||||
app.use(session({
|
app.use(useUnless(['/status', '/metrics'], session({
|
||||||
name: config.sessionName,
|
name: config.sessionName,
|
||||||
secret: config.sessionSecret,
|
secret: config.sessionSecret,
|
||||||
resave: false, // don't save session if unmodified
|
resave: false, // don't save session if unmodified
|
||||||
|
@ -159,7 +160,7 @@ app.use(session({
|
||||||
secure: config.useSSL || config.protocolUseSSL || false
|
secure: config.useSSL || config.protocolUseSSL || false
|
||||||
},
|
},
|
||||||
store: sessionStore
|
store: sessionStore
|
||||||
}))
|
})))
|
||||||
|
|
||||||
// session resumption
|
// session resumption
|
||||||
const tlsSessionStore = {}
|
const tlsSessionStore = {}
|
||||||
|
|
|
@ -25,3 +25,12 @@ exports.getImageMimeType = function getImageMimeType (imagePath) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.useUnless = function excludeRoute (paths, middleware) {
|
||||||
|
return function (req, res, next) {
|
||||||
|
if (paths.includes(req.path)) {
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
return middleware(req, res, next)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue