[bugfix] Unable to load bsm's files if path to bsm contains url special chars

This commit is contained in:
MathieuG-P
2024-11-01 17:20:23 +01:00
parent 681ddc6b0b
commit e07aacc9e8
+10 -12
View File
@@ -1,17 +1,15 @@
/* eslint import/prefer-default-export: off, import/no-mutable-exports: off */
import { URL } from "url";
import { pathToFileURL, URL } from "url";
import path from "path";
export let resolveHtmlPath: (htmlFileName: string) => string;
if (process.env.NODE_ENV === "development") {
const port = process.env.PORT || 1212;
resolveHtmlPath = (htmlFileName: string) => {
export function resolveHtmlPath (htmlFileName: string) {
if (process.env.NODE_ENV === "development") {
const port = process.env.PORT || 1212;
const url = new URL(`http://localhost:${port}/${htmlFileName}`);
return url.toString();
};
} else {
resolveHtmlPath = (htmlFileName: string) => {
return `file://${path.resolve(__dirname, "../renderer/", htmlFileName)}`;
};
}
}
const filePath = path.resolve(__dirname, "..", "renderer", htmlFileName);
return pathToFileURL(filePath).toString();
};