Skip to content

Commit 0894af4

Browse files
committed
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.
1 parent 23d0ceb commit 0894af4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/node/plugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as path from "path"
55
import * as semver from "semver"
66
import * as pluginapi from "../../typings/pluginapi"
77
import { version } from "./constants"
8+
import { replaceTemplates } from "./http"
89
import { proxy } from "./proxy"
910
import * as util from "./util"
1011
import { Router as WsRouter, WebsocketRouter, wss } from "./wsRouter"
@@ -23,6 +24,7 @@ require("module")._load = function (request: string, parent: object, isMain: boo
2324
field,
2425
Level,
2526
proxy,
27+
replaceTemplates,
2628
WsRouter,
2729
wss,
2830
}

typings/pluginapi.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,20 @@ export { express }
122122
*/
123123
export { field, Level, Logger }
124124

125+
/**
126+
* code-server's proxy server.
127+
*/
125128
export const proxy: ProxyServer
126129

130+
/**
131+
* Replace variables in HTML: TO, BASE, CS_STATIC_BASE, and OPTIONS.
132+
*/
133+
export function replaceTemplates<T extends object>(
134+
req: express.Request,
135+
content: string,
136+
extraOpts?: Omit<T, "base" | "csStaticBase" | "logLevel">,
137+
): string
138+
127139
/**
128140
* Your plugin module must have a top level export "plugin" that implements this interface.
129141
*

0 commit comments

Comments
 (0)