Skip to content

Commit 6ca4236

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 23a7c47 commit 6ca4236

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
@@ -123,8 +123,20 @@ export { express }
123123
*/
124124
export { field, Level, Logger }
125125

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

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

0 commit comments

Comments
 (0)