From 617e929e1af5b949da3caacd6df281a8fc99303d Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Fri, 29 Mar 2019 11:34:06 -0700 Subject: [PATCH] Fix relative paths and add error handling --- server/src/lib/utils/RequestUrlGetter.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/src/lib/utils/RequestUrlGetter.ts b/server/src/lib/utils/RequestUrlGetter.ts index ca3982c3..8660d801 100644 --- a/server/src/lib/utils/RequestUrlGetter.ts +++ b/server/src/lib/utils/RequestUrlGetter.ts @@ -1,7 +1,7 @@ -import Constants = require("../../../../../shared/constants"); +import Constants = require("../../../../shared/constants"); import Express = require("express"); -import GetHeader from "../../utils/GetHeader"; -import HasHeader from "../..//utils/HasHeader"; +import GetHeader from "./GetHeader"; +import HasHeader from "./HasHeader"; export class RequestUrlGetter { static getOriginalUrl(req: Express.Request): string { @@ -15,6 +15,11 @@ export class RequestUrlGetter { const port = GetHeader(req, Constants.HEADER_X_FORWARDED_PORT); const uri = GetHeader(req, Constants.HEADER_X_FORWARDED_URI); + if (!proto || !host || !port) { + throw new Error("Missing headers holding requested URL. Requires X-Original-Url or X-Forwarded-Proto, X-Forwarded-Host, and X-Forwarded-Port") + } + return "${proto}://${host}:${port}${uri}"; + } }