( req: express.Request, content: string, extraOpts?: Omit<T, "base" | "csStaticBase" | "logLevel">, )
| 59 | * Replace common variable strings in HTML templates. |
| 60 | */ |
| 61 | export 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. |
no test coverage detected