diff --git a/README.md b/README.md index f2981b3a..a6bdce4c 100644 --- a/README.md +++ b/README.md @@ -295,7 +295,7 @@ If you are specifically building a theme to integrate with an app or a website t to first browse unauthenticated before logging in, you will get a significant performance boost if you jump through those hoops: -- Provide the url of your app in the `homepage` field of package.json. [ex](https://github.com/garronej/keycloakify-demo-app/blob/7847cc70ef374ab26a6cc7953461cf25603e9a6d/package.json#L2) +- Provide the url of your app in the `homepage` field of package.json. [ex](https://github.com/garronej/keycloakify-demo-app/blob/7847cc70ef374ab26a6cc7953461cf25603e9a6d/package.json#L2) or in a `public/CNAME` file. [ex](https://github.com/garronej/keycloakify-demo-app/blob/main/public/CNAME). - Build the theme using `npx build-keycloak-theme --external-assets` [ex](https://github.com/garronej/keycloakify-demo-app/blob/7847cc70ef374ab26a6cc7953461cf25603e9a6d/.github/workflows/ci.yaml#L21) - Enable [long-term assets caching](https://create-react-app.dev/docs/production-build/#static-file-caching) on the server hosting your app. - Make sure not to build your app and the keycloak theme separately diff --git a/src/bin/build-keycloak-theme/build-keycloak-theme.ts b/src/bin/build-keycloak-theme/build-keycloak-theme.ts index f32ae600..39a06abc 100644 --- a/src/bin/build-keycloak-theme/build-keycloak-theme.ts +++ b/src/bin/build-keycloak-theme/build-keycloak-theme.ts @@ -4,6 +4,7 @@ import { join as pathJoin, relative as pathRelative, basename as pathBasename } import * as child_process from "child_process"; import { generateDebugFiles, containerLaunchScriptBasename } from "./generateDebugFiles"; import { URL } from "url"; +import * as fs from "fs"; type ParsedPackageJson = { name: string; @@ -41,7 +42,17 @@ export function main() { const url = (() => { const { homepage } = parsedPackageJson; - return homepage === undefined ? undefined : new URL(homepage); + if (homepage !== undefined) { + return new URL(homepage); + } + + const cnameFilePath = pathJoin(reactProjectDirPath, "public", "CNAME"); + + if (fs.existsSync(cnameFilePath)) { + return new URL(fs.readFileSync(cnameFilePath).toString("utf8").replace(/\s+$/, "")); + } + + return undefined; })(); return {