mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-01 00:18:14 +01:00
always set req.originalHostPrefix
This commit is contained in:
parent
9b8e059efe
commit
a8ab8badd5
@ -251,18 +251,17 @@ class Server {
|
|||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
// if RouterBasePath is set, modify all requests to include the base path
|
// if RouterBasePath is set, modify all requests to include the base path
|
||||||
if (global.RouterBasePath) {
|
app.use((req, res, next) => {
|
||||||
app.use((req, res, next) => {
|
const urlStartsWithRouterBasePath = req.url.startsWith(global.RouterBasePath)
|
||||||
const host = req.get('host')
|
const host = req.get('host')
|
||||||
const protocol = req.secure || req.get('x-forwarded-proto') === 'https' ? 'https' : 'http'
|
const protocol = req.secure || req.get('x-forwarded-proto') === 'https' ? 'https' : 'http'
|
||||||
const prefix = req.url.startsWith(global.RouterBasePath) ? global.RouterBasePath : ''
|
const prefix = urlStartsWithRouterBasePath ? global.RouterBasePath : ''
|
||||||
req.originalHostPrefix = `${protocol}://${host}${prefix}`
|
req.originalHostPrefix = `${protocol}://${host}${prefix}`
|
||||||
if (!req.url.startsWith(global.RouterBasePath)) {
|
if (!urlStartsWithRouterBasePath) {
|
||||||
req.url = `${global.RouterBasePath}${req.url}`
|
req.url = `${global.RouterBasePath}${req.url}`
|
||||||
}
|
}
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
}
|
|
||||||
app.use(global.RouterBasePath, router)
|
app.use(global.RouterBasePath, router)
|
||||||
app.disable('x-powered-by')
|
app.disable('x-powered-by')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user