Skip to content

Commit

Permalink
feat: customizable favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Aug 29, 2023
1 parent 5f67a1f commit 79e7723
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import express, { Request, Response } from "express"
import { engine } from "express-handlebars"
import * as fs from "fs"
import * as https from "https"
import { handlebarsHelpers } from "./pkg"
import { addFavicon, defaultConfig, handlebarsHelpers } from "./pkg"
import { middleware as middlewareLogger } from "./pkg/logger"
import {
register404Route,
Expand All @@ -31,6 +31,7 @@ const router = express.Router()

app.use(middlewareLogger)
app.use(cookieParser())
app.use(addFavicon(defaultConfig))
app.set("view engine", "hbs")

app.engine(
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const defaultConfig: RouteOptionsCreator = () => {
return {
apiBaseUrl: apiBaseUrl,
kratosBrowserUrl: apiBaseUrl,
faviconUrl: "favico.png",
faviconType: "image/png",
...sdk,
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/pkg/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ export const requireAuth =
})
}

export const addFavicon =
(createHelpers: RouteOptionsCreator) =>
(req: Request, res: Response, next: NextFunction) => {
const { faviconUrl, faviconType } = createHelpers(req, res)
res.locals.faviconUrl = faviconUrl
res.locals.faviconType = faviconType

next()
}

/**
* Sets the session in the request. If no session is found,
* the request still succeeds.
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface RouteOptions {
apiBaseUrl: string
kratosBrowserUrl: string
logoUrl?: string
faviconUrl?: string
faviconType?: string
theme?: Theme
}

Expand Down
5 changes: 4 additions & 1 deletion src/routes/recovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export const createRecoveryRoute: RouteCreator =
res.locals.projectName = "Recover account"

const { flow, return_to = "" } = req.query
const { frontend, kratosBrowserUrl, logoUrl } = createHelpers(req, res)
const { frontend, kratosBrowserUrl, logoUrl, faviconUrl, faviconType } =
createHelpers(req, res)
res.locals.faviconUrl = faviconUrl
res.locals.faviconType = faviconType
const initFlowUrl = getUrlForFlow(
kratosBrowserUrl,
"recovery",
Expand Down
2 changes: 1 addition & 1 deletion views/layouts/auth.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html lang='en'>
<html lang="en">
<head>
{{> standard_headers}}
<link type="text/css" rel='stylesheet' href="auth-layout.css" />
Expand Down
2 changes: 1 addition & 1 deletion views/partials/standard_headers.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<meta content="width=device-width, initial-scale=1" name="viewport" />
<link rel="icon" type="image/png" href="favico.png" />
<link rel="icon" href="{{{faviconUrl}}}" type="{{{faviconType}}}" />
<meta charset="utf-8" />
<title>{{projectName}}</title>
{{! CSS Reset}}
Expand Down

0 comments on commit 79e7723

Please sign in to comment.