fix(core): fix hooks URLs no longer added to index.html (#4262)

🐛 Fix hooks URLs no longer added to `index.html`
This commit is contained in:
Iván Ovejero 2022-10-04 18:40:01 +02:00 committed by GitHub
parent e30c78febe
commit cc2a2e438b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1789,16 +1789,16 @@ class App {
const editorUiDistDir = pathJoin(pathDirname(require.resolve('n8n-editor-ui')), 'dist'); const editorUiDistDir = pathJoin(pathDirname(require.resolve('n8n-editor-ui')), 'dist');
const generatedStaticDir = pathJoin(__dirname, '../public'); const generatedStaticDir = pathJoin(__dirname, '../public');
const firstLinkedScriptSegment = '<link href="/js/'; const closingTitleTag = '</title>';
const compileFile = async (fileName: string) => { const compileFile = async (fileName: string) => {
const filePath = pathJoin(editorUiDistDir, fileName); const filePath = pathJoin(editorUiDistDir, fileName);
if (/(index.html)|.*\.(js|css)/.test(filePath) && existsSync(filePath)) { if (/(index\.html)|.*\.(js|css)/.test(filePath) && existsSync(filePath)) {
const srcFile = await readFile(filePath, 'utf8'); const srcFile = await readFile(filePath, 'utf8');
let payload = srcFile.replace(basePathRegEx, n8nPath); let payload = srcFile.replace(basePathRegEx, n8nPath);
if (filePath === 'index.html') { if (filePath.endsWith('index.html')) {
payload = payload payload = payload
.replace(/\/favicon.ico/g, `${n8nPath}favicon.ico`) .replace(/\/favicon\.ico/g, `${n8nPath}favicon.ico`)
.replace(firstLinkedScriptSegment, scriptsString + firstLinkedScriptSegment); .replace(closingTitleTag, closingTitleTag + scriptsString);
} }
const destFile = pathJoin(generatedStaticDir, fileName); const destFile = pathJoin(generatedStaticDir, fileName);
await mkdir(pathDirname(destFile), { recursive: true }); await mkdir(pathDirname(destFile), { recursive: true });