···11+// This file is part of Laurali <https://github.com/gemrest/laurali>.
22+// Copyright (C) 2022-2022 Fuwn <contact@fuwn.me>
33+//
44+// This program is free software: you can redistribute it and/or modify
55+// it under the terms of the GNU General Public License as published by
66+// the Free Software Foundation, version 3.
77+//
88+// This program is distributed in the hope that it will be useful, but
99+// WITHOUT ANY WARRANTY; without even the implied warranty of
1010+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1111+// General Public License for more details.
1212+//
1313+// You should have received a copy of the GNU General Public License
1414+// along with this program. If not, see <http://www.gnu.org/licenses/>.
1515+//
1616+// Copyright (C) 2022-2022 Fuwn <contact@fuwn.me>
1717+// SPDX-License-Identifier: GPL-3.0-only
1818+1919+/** Configuration options of a `Server`'s HTTP proxy */
2020+export interface ProxyConfiguration {
2121+ /** Allow Laurali to proxy */
2222+ enable?: boolean;
2323+ /**
2424+ * The base URL of the HTTP proxy server
2525+ * @default "https://fuwn/me/proxy/"
2626+ */
2727+ baseURL?: string;
2828+ /**
2929+ * The hostname of **this** Laurali server
3030+ * @default ServerConfiguration.hostname
3131+ */
3232+ hostname?: string;
3333+}
3434+3535+/** Configuration options of a `Server` */
3636+export interface ServerConfiguration {
3737+ /** The port a `Server` will listen on */
3838+ port?: number;
3939+ /** The hostname a `Server` will identify as */
4040+ hostname?: string;
4141+ /** Proxy your Gemini content by specifying an HTTP proxy */
4242+ proxy?: ProxyConfiguration;
4343+}
+1
laurali/mod.ts
···1616// Copyright (C) 2022-2022 Fuwn <contact@fuwn.me>
1717// SPDX-License-Identifier: GPL-3.0-only
18181919+export * from "./configuration.ts";
1920export * from "./decorators.ts";
2021export * from "./hooks.ts";
2122export * from "./server.ts";
+19-8
laurali/server.ts
···1616// Copyright (C) 2022-2022 Fuwn <contact@fuwn.me>
1717// SPDX-License-Identifier: GPL-3.0-only
18181919+import { ServerConfiguration } from "./configuration.ts";
1920import { Hook } from "./hooks.ts";
2020-2121-/** Configuration options of a `Server` */
2222-export interface ServerConfiguration {
2323- /** The port a `Server` will listen on */
2424- port?: number;
2525- /** The hostname a `Server` will identify as */
2626- hostname?: string;
2727-}
28212922/** The base Laurali server to be extended upon */
3023export abstract class Server {
···6558 certFile,
6659 keyFile,
6760 });
6161+6262+ if (config?.proxy?.enable) {
6363+ if (config.proxy.baseURL === undefined) {
6464+ throw new Error("ProxyConfiguration is missing proxy baseURL");
6565+ }
6666+6767+ this.#proxy(config.proxy.baseURL, config.proxy.hostname || hostname);
6868+ }
6969+ }
7070+7171+ async #proxy(baseURL: string, host: string) {
7272+ const server = Deno.listen({ port: 8080 });
7373+7474+ for await (const c of server) {
7575+ for await (const r of Deno.serveHttp(c)) {
7676+ r.respondWith(Response.redirect(baseURL + host));
7777+ }
7878+ }
6879 }
69807081 /** Add a route function to the `Server` */