mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-28 09:20:55 -05:00
17 lines
605 B
TypeScript
17 lines
605 B
TypeScript
|
import { NextFunction, Request, Response } from 'express'
|
||
|
import { config } from '../../config'
|
||
|
|
||
|
export default function (req: Request, res: Response, next: NextFunction): void {
|
||
|
if (req.method === 'GET' && req.path.substr(-1) === '/' && req.path.length > 1) {
|
||
|
const queryString: string = req.url.slice(req.path.length)
|
||
|
const urlPath: string = req.path.slice(0, -1)
|
||
|
let serverURL: string = config.serverURL
|
||
|
if (config.urlPath) {
|
||
|
serverURL = serverURL.slice(0, -(config.urlPath.length + 1))
|
||
|
}
|
||
|
res.redirect(301, serverURL + urlPath + queryString)
|
||
|
} else {
|
||
|
next()
|
||
|
}
|
||
|
}
|