mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-22 09:11:41 +00:00
34 lines
844 B
JavaScript
34 lines
844 B
JavaScript
/**
|
|
* Whether the request was made over HTTPS.
|
|
* Uses Express `req.secure` and a strict `x-forwarded-proto === 'https'` check.
|
|
*
|
|
* @param {import('express').Request} req
|
|
* @returns {boolean}
|
|
*/
|
|
function isRequestSecure(req) {
|
|
return req.secure || req.get('x-forwarded-proto') === 'https'
|
|
}
|
|
|
|
/**
|
|
* @param {import('express').Request} req
|
|
* @returns {'https' | 'http'}
|
|
*/
|
|
function getRequestProtocol(req) {
|
|
return isRequestSecure(req) ? 'https' : 'http'
|
|
}
|
|
|
|
/**
|
|
* @param {import('express').Request} req
|
|
* @returns {{ protocol: 'https' | 'http', host: string, origin: string }}
|
|
*/
|
|
function getRequestOrigin(req) {
|
|
const protocol = getRequestProtocol(req)
|
|
const host = req.get('host')
|
|
return { protocol, host, origin: `${protocol}://${host}` }
|
|
}
|
|
|
|
module.exports = {
|
|
isRequestSecure,
|
|
getRequestProtocol,
|
|
getRequestOrigin
|
|
}
|