feat: use --app-name in error page title (#7693)

This commit is contained in:
Luna Ops
2026-03-12 05:43:45 +08:00
committed by GitHub
parent a6d80dc434
commit 24ea70ac88
7 changed files with 49 additions and 10 deletions

View File

@@ -11,7 +11,7 @@
content="style-src 'self'; manifest-src 'self'; img-src 'self' data:; font-src 'self' data:;"
/>
<meta name="color-scheme" content="light dark" />
<title>{{ERROR_TITLE}} - code-server</title>
<title>{{ERROR_TITLE}} - {{APP_NAME}}</title>
<link rel="icon" href="{{CS_STATIC_BASE}}/src/browser/media/favicon-dark-support.svg" />
<link rel="alternate icon" href="{{CS_STATIC_BASE}}/src/browser/media/favicon.ico" />
<link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />

View File

@@ -519,6 +519,7 @@ export interface DefaultedArgs extends ConfigArgs {
"extensions-dir": string
"user-data-dir": string
"session-socket": string
"app-name": string
/* Positional arguments. */
_: string[]
}
@@ -665,6 +666,10 @@ export async function setDefaults(cliArgs: UserProvidedArgs, configArgs?: Config
}
args["proxy-domain"] = finalProxies
if (!args["app-name"]) {
args["app-name"] = "code-server"
}
args._ = getResolvedPathsFromArgs(args)
return {

View File

@@ -57,7 +57,8 @@ export const errorHandler: express.ErrorRequestHandler = async (err, req, res, n
replaceTemplates(req, content)
.replace(/{{ERROR_TITLE}}/g, statusCode.toString())
.replace(/{{ERROR_HEADER}}/g, statusCode.toString())
.replace(/{{ERROR_BODY}}/g, escapeHtml(err.message)),
.replace(/{{ERROR_BODY}}/g, escapeHtml(err.message))
.replace(/{{APP_NAME}}/g, req.args["app-name"]),
)
} else {
res.json({

View File

@@ -29,8 +29,7 @@ const getRoot = async (req: Request, error?: Error): Promise<string> => {
const content = await fs.readFile(path.join(rootPath, "src/browser/pages/login.html"), "utf8")
const locale = req.args["locale"] || "en"
i18n.changeLanguage(locale)
const appName = req.args["app-name"] || "code-server"
const welcomeText = req.args["welcome-text"] || (i18n.t("WELCOME", { app: appName }) as string)
const welcomeText = req.args["welcome-text"] || (i18n.t("WELCOME", { app: req.args["app-name"] }) as string)
// Determine password message using i18n
let passwordMsg = i18n.t("LOGIN_PASSWORD", { configFile: req.args.config })
@@ -43,7 +42,7 @@ const getRoot = async (req: Request, error?: Error): Promise<string> => {
return replaceTemplates(
req,
content
.replace(/{{I18N_LOGIN_TITLE}}/g, i18n.t("LOGIN_TITLE", { app: appName }))
.replace(/{{I18N_LOGIN_TITLE}}/g, i18n.t("LOGIN_TITLE", { app: req.args["app-name"] }))
.replace(/{{WELCOME_TEXT}}/g, welcomeText)
.replace(/{{PASSWORD_MSG}}/g, passwordMsg)
.replace(/{{I18N_LOGIN_BELOW}}/g, i18n.t("LOGIN_BELOW"))

View File

@@ -172,7 +172,6 @@ router.get("/", ensureVSCodeLoaded, async (req, res, next) => {
})
router.get("/manifest.json", async (req, res) => {
const appName = req.args["app-name"] || "code-server"
res.writeHead(200, { "Content-Type": "application/manifest+json" })
res.end(
@@ -180,8 +179,8 @@ router.get("/manifest.json", async (req, res) => {
req,
JSON.stringify(
{
name: appName,
short_name: appName,
name: req.args["app-name"],
short_name: req.args["app-name"],
start_url: ".",
display: "fullscreen",
display_override: ["window-controls-overlay"],