From 22d194515a22297a393ad320093e87bcceb41049 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 28 Jan 2021 14:24:07 -0600 Subject: [PATCH] Expose replaceTemplates to plugins This is mainly so they can get relative paths in their HTML, in particular code-server's static base so they can use the favicon and service worker. --- src/node/plugin.ts | 2 ++ typings/pluginapi.d.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/node/plugin.ts b/src/node/plugin.ts index cf06d3d7..70220103 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -5,6 +5,7 @@ import * as path from "path" import * as semver from "semver" import * as pluginapi from "../../typings/pluginapi" import { version } from "./constants" +import { replaceTemplates } from "./http" import { proxy } from "./proxy" import * as util from "./util" import { Router as WsRouter, WebsocketRouter, wss } from "./wsRouter" @@ -23,6 +24,7 @@ require("module")._load = function (request: string, parent: object, isMain: boo field, Level, proxy, + replaceTemplates, WsRouter, wss, } diff --git a/typings/pluginapi.d.ts b/typings/pluginapi.d.ts index b0f6bd02..fbac3af9 100644 --- a/typings/pluginapi.d.ts +++ b/typings/pluginapi.d.ts @@ -123,8 +123,20 @@ export { express } */ export { field, Level, Logger } +/** + * code-server's proxy server. + */ export const proxy: ProxyServer +/** + * Replace variables in HTML: TO, BASE, CS_STATIC_BASE, and OPTIONS. + */ +export function replaceTemplates( + req: express.Request, + content: string, + extraOpts?: Omit, +): string + /** * Your plugin module must have a top level export "plugin" that implements this interface. *