🧁 An object-oriented Gemini server for Deno!
gemini-protocol deno typescript gemini
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(server): optional http proxy redirect

Fuwn 630cb6f8 476160a5

+70 -9
+7 -1
examples/my_cool_server.ts
··· 77 77 } 78 78 } 79 79 80 - (new MyCoolServer(".laurali/public.pem", ".laurali/private.pem")).listen(); 80 + (new MyCoolServer(".laurali/public.pem", ".laurali/private.pem", { 81 + proxy: { 82 + enable: true, 83 + baseURL: "https://fuwn.me/proxy/", 84 + hostname: "fuwn.me", 85 + }, 86 + })).listen();
+43
laurali/configuration.ts
··· 1 + // This file is part of Laurali <https://github.com/gemrest/laurali>. 2 + // Copyright (C) 2022-2022 Fuwn <contact@fuwn.me> 3 + // 4 + // This program is free software: you can redistribute it and/or modify 5 + // it under the terms of the GNU General Public License as published by 6 + // the Free Software Foundation, version 3. 7 + // 8 + // This program is distributed in the hope that it will be useful, but 9 + // WITHOUT ANY WARRANTY; without even the implied warranty of 10 + // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 + // General Public License for more details. 12 + // 13 + // You should have received a copy of the GNU General Public License 14 + // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 + // 16 + // Copyright (C) 2022-2022 Fuwn <contact@fuwn.me> 17 + // SPDX-License-Identifier: GPL-3.0-only 18 + 19 + /** Configuration options of a `Server`'s HTTP proxy */ 20 + export interface ProxyConfiguration { 21 + /** Allow Laurali to proxy */ 22 + enable?: boolean; 23 + /** 24 + * The base URL of the HTTP proxy server 25 + * @default "https://fuwn/me/proxy/" 26 + */ 27 + baseURL?: string; 28 + /** 29 + * The hostname of **this** Laurali server 30 + * @default ServerConfiguration.hostname 31 + */ 32 + hostname?: string; 33 + } 34 + 35 + /** Configuration options of a `Server` */ 36 + export interface ServerConfiguration { 37 + /** The port a `Server` will listen on */ 38 + port?: number; 39 + /** The hostname a `Server` will identify as */ 40 + hostname?: string; 41 + /** Proxy your Gemini content by specifying an HTTP proxy */ 42 + proxy?: ProxyConfiguration; 43 + }
+1
laurali/mod.ts
··· 16 16 // Copyright (C) 2022-2022 Fuwn <contact@fuwn.me> 17 17 // SPDX-License-Identifier: GPL-3.0-only 18 18 19 + export * from "./configuration.ts"; 19 20 export * from "./decorators.ts"; 20 21 export * from "./hooks.ts"; 21 22 export * from "./server.ts";
+19 -8
laurali/server.ts
··· 16 16 // Copyright (C) 2022-2022 Fuwn <contact@fuwn.me> 17 17 // SPDX-License-Identifier: GPL-3.0-only 18 18 19 + import { ServerConfiguration } from "./configuration.ts"; 19 20 import { Hook } from "./hooks.ts"; 20 - 21 - /** Configuration options of a `Server` */ 22 - export interface ServerConfiguration { 23 - /** The port a `Server` will listen on */ 24 - port?: number; 25 - /** The hostname a `Server` will identify as */ 26 - hostname?: string; 27 - } 28 21 29 22 /** The base Laurali server to be extended upon */ 30 23 export abstract class Server { ··· 65 58 certFile, 66 59 keyFile, 67 60 }); 61 + 62 + if (config?.proxy?.enable) { 63 + if (config.proxy.baseURL === undefined) { 64 + throw new Error("ProxyConfiguration is missing proxy baseURL"); 65 + } 66 + 67 + this.#proxy(config.proxy.baseURL, config.proxy.hostname || hostname); 68 + } 69 + } 70 + 71 + async #proxy(baseURL: string, host: string) { 72 + const server = Deno.listen({ port: 8080 }); 73 + 74 + for await (const c of server) { 75 + for await (const r of Deno.serveHttp(c)) { 76 + r.respondWith(Response.redirect(baseURL + host)); 77 + } 78 + } 68 79 } 69 80 70 81 /** Add a route function to the `Server` */