MCPcopy Index your code
hub / github.com/coder/code-server / replaceTemplates

Function replaceTemplates

src/node/http.ts:61–76  ·  view source on GitHub ↗
(
  req: express.Request,
  content: string,
  extraOpts?: Omit<T, "base" | "csStaticBase" | "logLevel">,
)

Source from the content-addressed store, hash-verified

59 * Replace common variable strings in HTML templates.
60 */
61export const replaceTemplates = <T extends object>(
62 req: express.Request,
63 content: string,
64 extraOpts?: Omit<T, "base" | "csStaticBase" | "logLevel">,
65): string => {
66 const serverOptions: ClientConfiguration = {
67 ...createClientConfiguration(req),
68 ...extraOpts,
69 }
70
71 return content
72 .replace(/{{TO}}/g, (typeof req.query.to === "string" && escapeHtml(req.query.to)) || "/")
73 .replace(/{{BASE}}/g, serverOptions.base)
74 .replace(/{{CS_STATIC_BASE}}/g, serverOptions.csStaticBase)
75 .replace("{{OPTIONS}}", () => escapeJSON(serverOptions))
76}
77
78/**
79 * Throw an error if proxy is not enabled. Call `next` if provided.

Callers 3

getRootFunction · 0.90
vscode.tsFile · 0.90
errorHandlerFunction · 0.90

Calls 3

escapeHtmlFunction · 0.90
escapeJSONFunction · 0.90

Tested by

no test coverage detected