Skip to content

Commit 8188b29

Browse files
authored
feat: customizable favicon (#282)
1 parent 94bb41b commit 8188b29

File tree

7 files changed

+22
-4
lines changed

7 files changed

+22
-4
lines changed

src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import express, { Request, Response } from "express"
55
import { engine } from "express-handlebars"
66
import * as fs from "fs"
77
import * as https from "https"
8-
import { handlebarsHelpers } from "./pkg"
8+
import { addFavicon, defaultConfig, handlebarsHelpers } from "./pkg"
99
import { middleware as middlewareLogger } from "./pkg/logger"
1010
import {
1111
register404Route,
@@ -31,6 +31,7 @@ const router = express.Router()
3131

3232
app.use(middlewareLogger)
3333
app.use(cookieParser())
34+
app.use(addFavicon(defaultConfig))
3435
app.set("view engine", "hbs")
3536

3637
app.engine(

src/pkg/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const defaultConfig: RouteOptionsCreator = () => {
3030
return {
3131
apiBaseUrl: apiBaseUrl,
3232
kratosBrowserUrl: apiBaseUrl,
33+
faviconUrl: "favico.png",
34+
faviconType: "image/png",
3335
...sdk,
3436
}
3537
}

src/pkg/middleware.ts

+10
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ export const requireAuth =
7777
})
7878
}
7979

80+
export const addFavicon =
81+
(createHelpers: RouteOptionsCreator) =>
82+
(req: Request, res: Response, next: NextFunction) => {
83+
const { faviconUrl, faviconType } = createHelpers(req, res)
84+
res.locals.faviconUrl = faviconUrl
85+
res.locals.faviconType = faviconType
86+
87+
next()
88+
}
89+
8090
/**
8191
* Sets the session in the request. If no session is found,
8292
* the request still succeeds.

src/pkg/route.ts

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export interface RouteOptions {
1111
apiBaseUrl: string
1212
kratosBrowserUrl: string
1313
logoUrl?: string
14+
faviconUrl?: string
15+
faviconType?: string
1416
theme?: Theme
1517
}
1618

src/routes/recovery.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export const createRecoveryRoute: RouteCreator =
1717
res.locals.projectName = "Recover account"
1818

1919
const { flow, return_to = "" } = req.query
20-
const { frontend, kratosBrowserUrl, logoUrl } = createHelpers(req, res)
20+
const { frontend, kratosBrowserUrl, logoUrl, faviconUrl, faviconType } =
21+
createHelpers(req, res)
22+
res.locals.faviconUrl = faviconUrl
23+
res.locals.faviconType = faviconType
2124
const initFlowUrl = getUrlForFlow(
2225
kratosBrowserUrl,
2326
"recovery",

views/layouts/auth.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<html lang='en'>
1+
<html lang="en">
22
<head>
33
{{> standard_headers}}
44
<link type="text/css" rel='stylesheet' href="auth-layout.css" />

views/partials/standard_headers.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<meta content="width=device-width, initial-scale=1" name="viewport" />
2-
<link rel="icon" type="image/png" href="favico.png" />
2+
<link rel="icon" href="{{{faviconUrl}}}" type="{{{faviconType}}}" />
33
<meta charset="utf-8" />
44
<title>{{projectName}}</title>
55
{{! CSS Reset}}

0 commit comments

Comments
 (0)