Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: customizable favicon #282

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading