diff options
| author | Fuwn <[email protected]> | 2022-05-17 11:43:10 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-05-17 11:43:17 +0000 |
| commit | 630cb6f89a8519036fdd31eb891348aebcbf01eb (patch) | |
| tree | 032cefae757baf9ab41ada474f5830af9eb5c9b0 /laurali/server.ts | |
| parent | fix(decorators): assumed route format (diff) | |
| download | archived-laurali-main.tar.xz archived-laurali-main.zip | |
feat(server): optional http proxy redirectHEAD0.1.2origin/mainmain
Diffstat (limited to 'laurali/server.ts')
| -rw-r--r-- | laurali/server.ts | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/laurali/server.ts b/laurali/server.ts index b647dc2..f8c641f 100644 --- a/laurali/server.ts +++ b/laurali/server.ts @@ -16,16 +16,9 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only +import { ServerConfiguration } from "./configuration.ts"; import { Hook } from "./hooks.ts"; -/** Configuration options of a `Server` */ -export interface ServerConfiguration { - /** The port a `Server` will listen on */ - port?: number; - /** The hostname a `Server` will identify as */ - hostname?: string; -} - /** The base Laurali server to be extended upon */ export abstract class Server { /** @@ -65,6 +58,24 @@ export abstract class Server { certFile, keyFile, }); + + if (config?.proxy?.enable) { + if (config.proxy.baseURL === undefined) { + throw new Error("ProxyConfiguration is missing proxy baseURL"); + } + + this.#proxy(config.proxy.baseURL, config.proxy.hostname || hostname); + } + } + + async #proxy(baseURL: string, host: string) { + const server = Deno.listen({ port: 8080 }); + + for await (const c of server) { + for await (const r of Deno.serveHttp(c)) { + r.respondWith(Response.redirect(baseURL + host)); + } + } } /** Add a route function to the `Server` */ |