Archived
1
0

feat: add customization options for the login page (#5633)

* add customization options for the login page

* add unit tests

* add test for correct welcome text when none is set but app-name is

Signed-off-by: niwla23 <46248939+niwla23@users.noreply.github.com>

* add test for no app-name set and check in title too

Signed-off-by: niwla23 <46248939+niwla23@users.noreply.github.com>

Signed-off-by: niwla23 <46248939+niwla23@users.noreply.github.com>
Co-authored-by: Joe Previte <jjprevite@gmail.com>
This commit is contained in:
Alwin Lohrie
2022-10-14 00:32:20 +02:00
committed by GitHub
parent 71a127a62b
commit 714afe0cc7
5 changed files with 68 additions and 3 deletions

View File

@ -28,6 +28,8 @@ export class RateLimiter {
const getRoot = async (req: Request, error?: Error): Promise<string> => {
const content = await fs.readFile(path.join(rootPath, "src/browser/pages/login.html"), "utf8")
const appName = req.args["app-name"] || "code-server"
const welcomeText = req.args["welcome-text"] || `Welcome to ${appName}`
let passwordMsg = `Check the config file at ${humanPath(os.homedir(), req.args.config)} for the password.`
if (req.args.usingEnvPassword) {
passwordMsg = "Password was set from $PASSWORD."
@ -38,6 +40,8 @@ const getRoot = async (req: Request, error?: Error): Promise<string> => {
return replaceTemplates(
req,
content
.replace(/{{APP_NAME}}/g, appName)
.replace(/{{WELCOME_TEXT}}/g, welcomeText)
.replace(/{{PASSWORD_MSG}}/g, passwordMsg)
.replace(/{{ERROR}}/, error ? `<div class="error">${escapeHtml(error.message)}</div>` : ""),
)