Skip to content

Commit

Permalink
added fallback to index.html option
Browse files Browse the repository at this point in the history
  • Loading branch information
matthme committed Oct 16, 2024
1 parent 158449d commit 925ac12
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions kangaroo.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineConfig({
version: "0.1.0",
macOSCodeSigning: false,
windowsEVCodeSigning: false,
fallbackToIndexHtml: true,
bins: {
holochain: {
version: "0.3.3",
Expand Down
5 changes: 5 additions & 0 deletions src/main/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export type KangarooConfig = {
* in the format of this guide: https://melatonin.dev/blog/how-to-code-sign-windows-installers-with-an-ev-cert-on-github-actions/
*/
windowsEVCodeSigning: boolean,
/**
* Fall back to serving the index.html if a resources is not found. Often required for router-based
* frameworks like svelte-kit or vue-router
*/
fallbackToIndexHtml: boolean,
// /**
// * Whether or not the app should have the user set up a password.
// */
Expand Down
11 changes: 7 additions & 4 deletions src/main/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ export const createHappWindow = async (
ses.protocol.handle("webhapp", async (request) => {
const uriWithoutProtocol = request.url.slice("webhapp://".length);
const filePathComponents = uriWithoutProtocol.split("/").slice(1);
const filePath = path.join(...filePathComponents);
const relativeFilePath = path.join(...filePathComponents);
const absoluteFilePath = path.join(uiSource.path, relativeFilePath);

if (!filePath.endsWith("index.html")) {
const fallbackToIndexHtml = KANGAROO_CONFIG.fallbackToIndexHtml ? !fs.existsSync(absoluteFilePath) : false;

if (!relativeFilePath.endsWith("index.html") && !fallbackToIndexHtml) {
return net.fetch(
url.pathToFileURL(path.join(uiSource.path, filePath)).toString()
url.pathToFileURL(absoluteFilePath).toString()
);
} else {
const indexHtmlResponse = await net.fetch(url.pathToFileURL(path.join(uiSource.path, filePath)).toString());
const indexHtmlResponse = await net.fetch(url.pathToFileURL(absoluteFilePath).toString());
const content = await indexHtmlResponse.text();
let modifiedContent = content.replace(
"<head>",
Expand Down

0 comments on commit 925ac12

Please sign in to comment.