From 79e772312ff24f8f536e42082c33691b8a185d66 Mon Sep 17 00:00:00 2001 From: Henning Perl Date: Tue, 29 Aug 2023 09:03:38 +0200 Subject: [PATCH] feat: customizable favicon --- package-lock.json | 4 ++-- src/index.ts | 3 ++- src/pkg/index.ts | 2 ++ src/pkg/middleware.ts | 10 ++++++++++ src/pkg/route.ts | 2 ++ src/routes/recovery.ts | 5 ++++- views/layouts/auth.hbs | 2 +- views/partials/standard_headers.hbs | 2 +- 8 files changed, 24 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 94b12ba6..216e75c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ory/kratos-selfservice-ui-node", - "version": "0.13.0-6", + "version": "0.13.0-7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@ory/kratos-selfservice-ui-node", - "version": "0.13.0-6", + "version": "0.13.0-7", "license": "Apache-2.0", "dependencies": { "@ory/client": "1.1.41", diff --git a/src/index.ts b/src/index.ts index 7557c1c6..e74a9e91 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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, @@ -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( diff --git a/src/pkg/index.ts b/src/pkg/index.ts index 072c9ee8..87c72bf9 100644 --- a/src/pkg/index.ts +++ b/src/pkg/index.ts @@ -30,6 +30,8 @@ export const defaultConfig: RouteOptionsCreator = () => { return { apiBaseUrl: apiBaseUrl, kratosBrowserUrl: apiBaseUrl, + faviconUrl: "favico.png", + faviconType: "image/png", ...sdk, } } diff --git a/src/pkg/middleware.ts b/src/pkg/middleware.ts index 1335c950..ce889b29 100644 --- a/src/pkg/middleware.ts +++ b/src/pkg/middleware.ts @@ -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. diff --git a/src/pkg/route.ts b/src/pkg/route.ts index bcc5a995..74a6fb2f 100644 --- a/src/pkg/route.ts +++ b/src/pkg/route.ts @@ -11,6 +11,8 @@ export interface RouteOptions { apiBaseUrl: string kratosBrowserUrl: string logoUrl?: string + faviconUrl?: string + faviconType?: string theme?: Theme } diff --git a/src/routes/recovery.ts b/src/routes/recovery.ts index 29c8ee5e..62c9c866 100644 --- a/src/routes/recovery.ts +++ b/src/routes/recovery.ts @@ -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", diff --git a/views/layouts/auth.hbs b/views/layouts/auth.hbs index 939c2ed3..3c20b2e0 100644 --- a/views/layouts/auth.hbs +++ b/views/layouts/auth.hbs @@ -1,4 +1,4 @@ - + {{> standard_headers}} diff --git a/views/partials/standard_headers.hbs b/views/partials/standard_headers.hbs index c06cc680..cc19698f 100644 --- a/views/partials/standard_headers.hbs +++ b/views/partials/standard_headers.hbs @@ -1,5 +1,5 @@ - + {{projectName}} {{! CSS Reset}}