diff --git a/src/node/cli.ts b/src/node/cli.ts
index df843eda2cee..719295119a5e 100644
--- a/src/node/cli.ts
+++ b/src/node/cli.ts
@@ -84,6 +84,8 @@ export interface UserProvidedArgs extends UserProvidedCodeArgs {
"ignore-last-opened"?: boolean
link?: OptionalString
verbose?: boolean
+ "app-name"?: string
+ "welcome-text"?: string
/* Positional arguments. */
_?: string[]
}
@@ -233,7 +235,16 @@ export const options: Options
> = {
log: { type: LogLevel },
verbose: { type: "boolean", short: "vvv", description: "Enable verbose logging." },
-
+ "app-name": {
+ type: "string",
+ short: "an",
+ description: "The name to use in branding. Will be shown in titlebar and welcome message",
+ },
+ "welcome-text": {
+ type: "string",
+ short: "w",
+ description: "Text to show on login page",
+ },
link: {
type: OptionalString,
description: `
diff --git a/src/node/routes/login.ts b/src/node/routes/login.ts
index 262147232f81..633c34ba4e1f 100644
--- a/src/node/routes/login.ts
+++ b/src/node/routes/login.ts
@@ -28,6 +28,8 @@ export class RateLimiter {
const getRoot = async (req: Request, error?: Error): Promise => {
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 => {
return replaceTemplates(
req,
content
+ .replace(/{{APP_NAME}}/g, appName)
+ .replace(/{{WELCOME_TEXT}}/g, welcomeText)
.replace(/{{PASSWORD_MSG}}/g, passwordMsg)
.replace(/{{ERROR}}/, error ? `${escapeHtml(error.message)}
` : ""),
)
From 28330e4c29e0eec16d176705e18b0f79d3fa3282 Mon Sep 17 00:00:00 2001
From: niwla23 <46248939+niwla23@users.noreply.github.com>
Date: Tue, 11 Oct 2022 15:54:07 +0200
Subject: [PATCH 2/4] add unit tests
---
test/unit/node/cli.test.ts | 4 ++++
test/unit/node/routes/login.test.ts | 22 ++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/test/unit/node/cli.test.ts b/test/unit/node/cli.test.ts
index 51e707001d8a..4afa404c03b7 100644
--- a/test/unit/node/cli.test.ts
+++ b/test/unit/node/cli.test.ts
@@ -67,6 +67,8 @@ describe("parser", () => {
"1",
"--verbose",
+ ["--app-name", "custom instance name"],
+ ["--welcome-text", "welcome to code"],
"2",
["--locale", "ja"],
@@ -123,6 +125,8 @@ describe("parser", () => {
socket: path.resolve("mumble"),
"socket-mode": "777",
verbose: true,
+ "app-name": "custom instance name",
+ "welcome-text": "welcome to code",
version: true,
"bind-addr": "192.169.0.1:8080",
})
diff --git a/test/unit/node/routes/login.test.ts b/test/unit/node/routes/login.test.ts
index b132c0e87e06..79cf0976caa2 100644
--- a/test/unit/node/routes/login.test.ts
+++ b/test/unit/node/routes/login.test.ts
@@ -92,5 +92,27 @@ describe("login", () => {
expect(htmlContent).toContain("Incorrect password")
})
+
+ it("should return correct app-name", async () => {
+ process.env.PASSWORD = previousEnvPassword
+ const appName = "testnäme"
+ const codeServer = await integration.setup([`--app-name=${appName}`], "")
+ const resp = await codeServer.fetch("/login", { method: "GET" })
+
+ const htmlContent = await resp.text()
+ expect(resp.status).toBe(200)
+ expect(htmlContent).toContain(appName)
+ })
+
+ it("should return correct welcome text", async () => {
+ process.env.PASSWORD = previousEnvPassword
+ const welcomeText = "Welcome to your code workspace! öäü🔐"
+ const codeServer = await integration.setup([`--welcome-text=${welcomeText}`], "")
+ const resp = await codeServer.fetch("/login", { method: "GET" })
+
+ const htmlContent = await resp.text()
+ expect(resp.status).toBe(200)
+ expect(htmlContent).toContain(welcomeText)
+ })
})
})
From 4e80591339c54c62b6398331784462c4f44f58ab Mon Sep 17 00:00:00 2001
From: niwla23 <46248939+niwla23@users.noreply.github.com>
Date: Tue, 11 Oct 2022 15:58:22 +0200
Subject: [PATCH 3/4] add test for correct welcome text when none is set but
app-name is
Signed-off-by: niwla23 <46248939+niwla23@users.noreply.github.com>
---
test/unit/node/routes/login.test.ts | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/test/unit/node/routes/login.test.ts b/test/unit/node/routes/login.test.ts
index 79cf0976caa2..f41813daf1a3 100644
--- a/test/unit/node/routes/login.test.ts
+++ b/test/unit/node/routes/login.test.ts
@@ -114,5 +114,16 @@ describe("login", () => {
expect(resp.status).toBe(200)
expect(htmlContent).toContain(welcomeText)
})
+
+ it("should return correct welcome text when none is set but app-name is", async () => {
+ process.env.PASSWORD = previousEnvPassword
+ const appName = "testnäme"
+ const codeServer = await integration.setup([`--app-name=${appName}`], "")
+ const resp = await codeServer.fetch("/login", { method: "GET" })
+
+ const htmlContent = await resp.text()
+ expect(resp.status).toBe(200)
+ expect(htmlContent).toContain(`Welcome to ${appName}`)
+ })
})
})
From e5c630b7c01149e23eff7fcc8db0df424207a5c8 Mon Sep 17 00:00:00 2001
From: niwla23 <46248939+niwla23@users.noreply.github.com>
Date: Tue, 11 Oct 2022 17:22:41 +0200
Subject: [PATCH 4/4] add test for no app-name set and check in title too
Signed-off-by: niwla23 <46248939+niwla23@users.noreply.github.com>
---
test/unit/node/routes/login.test.ts | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/test/unit/node/routes/login.test.ts b/test/unit/node/routes/login.test.ts
index f41813daf1a3..b2cf4465149d 100644
--- a/test/unit/node/routes/login.test.ts
+++ b/test/unit/node/routes/login.test.ts
@@ -101,7 +101,20 @@ describe("login", () => {
const htmlContent = await resp.text()
expect(resp.status).toBe(200)
- expect(htmlContent).toContain(appName)
+ expect(htmlContent).toContain(`${appName}`)
+ expect(htmlContent).toContain(`${appName} login`)
+ })
+
+ it("should return correct app-name when unset", async () => {
+ process.env.PASSWORD = previousEnvPassword
+ const appName = "code-server"
+ const codeServer = await integration.setup([], "")
+ const resp = await codeServer.fetch("/login", { method: "GET" })
+
+ const htmlContent = await resp.text()
+ expect(resp.status).toBe(200)
+ expect(htmlContent).toContain(`${appName}`)
+ expect(htmlContent).toContain(`${appName} login`)
})
it("should return correct welcome text", async () => {