Read public/CNAME for domain name in --externel-assets mode

This commit is contained in:
garronej 2022-01-18 18:52:52 +01:00
parent fabd48a22c
commit 11d6a2020f
2 changed files with 13 additions and 2 deletions

View File

@ -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 to first browse unauthenticated before logging in, you will get a significant
performance boost if you jump through those hoops: 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) - 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. - 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 - Make sure not to build your app and the keycloak theme separately

View File

@ -4,6 +4,7 @@ import { join as pathJoin, relative as pathRelative, basename as pathBasename }
import * as child_process from "child_process"; import * as child_process from "child_process";
import { generateDebugFiles, containerLaunchScriptBasename } from "./generateDebugFiles"; import { generateDebugFiles, containerLaunchScriptBasename } from "./generateDebugFiles";
import { URL } from "url"; import { URL } from "url";
import * as fs from "fs";
type ParsedPackageJson = { type ParsedPackageJson = {
name: string; name: string;
@ -41,7 +42,17 @@ export function main() {
const url = (() => { const url = (() => {
const { homepage } = parsedPackageJson; 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 { return {