diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/RouteManager.ts | 38 | ||||
-rw-r--r-- | src/server/index.ts | 6 | ||||
-rw-r--r-- | src/server/server_Initialization.ts | 24 |
3 files changed, 29 insertions, 39 deletions
diff --git a/src/server/RouteManager.ts b/src/server/RouteManager.ts index c88f3bb51..a8680c0c9 100644 --- a/src/server/RouteManager.ts +++ b/src/server/RouteManager.ts @@ -94,11 +94,9 @@ export default class RouteManager { sub instanceof RouteSubscriber && RouteManager.routes.push(sub.root); }); const isRelease = this._isRelease; - let redirected = ""; const supervised = async (req: Request, res: Response) => { let { user } = req; const { originalUrl: target } = req; - console.log("TARGET: " + target); if (process.env.DB === "MEM" && !user) { user = { id: "guest", email: "", userDocumentId: "guestDocId" }; } @@ -128,37 +126,13 @@ export default class RouteManager { res.redirect("/login"); } } - if (!res.headersSent && req.headers.referer?.includes("corsProxy")) { - const url = decodeURIComponent(req.headers.referer!); - const start = url.match(/.*corsProxy\//)![0]; - const original = url.replace(start, ""); - const theurl = original.match(/http[s]?:\/\/[^\/]*/)![0]; - const newdirect = start + encodeURIComponent(theurl + target); - console.log("REDIRECT: " + (theurl + target)); - res.redirect(newdirect); - } - else if (!res.headersSent) { - const which2 = RouteManager.routes.findIndex(r => (r !== "/" || r === target) && target.startsWith(r)); - const which = Array.from(registered.keys()).findIndex(r => (r !== "/" || r === target) && target.startsWith(r)); - console.log("WHICH = " + (which === -1 ? "" : Array.from(registered.keys())[which])); - if (which !== -1) { - setTimeout(() => { - console.log("handled:" + target); - if (!res.headersSent) { - console.log(red(`Initiating fallback for ${target}. Please remove dangling promise from route handler`)); - const warning = `request to ${target} fell through - this is a fallback response`; - res.send({ warning }); - } - }, 1000); - } - else { - console.log("unhandled:" + target); - res.end(); + setTimeout(() => { + if (!res.headersSent) { + console.log(red(`Initiating fallback for ${target}. Please remove dangling promise from route handler`)); + const warning = `request to ${target} fell through - this is a fallback response`; + res.send({ warning }); } - } else { - console.log("pre-sent:" + target); - res.end(); - } + }, 1000); }; const subscribe = (subscriber: RouteSubscriber | string) => { let route: string; diff --git a/src/server/index.ts b/src/server/index.ts index def36e922..10205314a 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -114,12 +114,6 @@ function routeSetter({ isRelease, addSupervisedRoute, logRegistrationOutcome }: } }); - addSupervisedRoute({ - method: Method.GET, - subscription: "/*", - secureHandler: ({ res }) => { - } - }); logRegistrationOutcome(); // initialize the web socket (bidirectional communication: if a user changes diff --git a/src/server/server_Initialization.ts b/src/server/server_Initialization.ts index bb661a124..3ba9cc474 100644 --- a/src/server/server_Initialization.ts +++ b/src/server/server_Initialization.ts @@ -20,7 +20,7 @@ import * as request from 'request'; import RouteSubscriber from './RouteSubscriber'; import { publicDirectory } from '.'; import { logPort, } from './ActionUtilities'; -import { timeMap } from './ApiManagers/UserManager'; +import { Utils } from '../Utils'; import { blue, yellow } from 'colors'; import * as cors from "cors"; @@ -61,9 +61,11 @@ export default async function InitializeServer(routeSetter: RouteSetter) { registerAuthenticationRoutes(app); registerCorsProxy(app); + const isRelease = determineEnvironment(); routeSetter(new RouteManager(app, isRelease)); + registerRelativePath(app); const serverPort = isRelease ? Number(process.env.serverPort) : 1050; const server = app.listen(serverPort, () => { @@ -153,3 +155,23 @@ function registerCorsProxy(server: express.Express) { }).pipe(res); }); } + +function registerRelativePath(server: express.Express) { + server.use("*", (req, res) => { + const target = req.originalUrl; + if (!res.headersSent && req.headers.referer?.includes("corsProxy")) { + const url = decodeURIComponent(req.headers.referer); + const start = url.match(/.*corsProxy\//)![0]; + const original = url.replace(start, ""); + const theurl = original.match(/http[s]?:\/\/[^\/]*/)![0]; + const newdirect = start + encodeURIComponent(theurl + target); + res.redirect(newdirect); + return; + } else if (target.startsWith("/search")) { + const newdirect = req.headers.referer + "corsProxy/" + encodeURIComponent("http://www.google.com" + target); + res.redirect(newdirect); + return; + } + res.end(); + }); +} |