From 25044547d64f66d3c3b6e59ce1bd59ea0e96fe46 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilev Date: Wed, 18 Jan 2023 16:30:44 +0800 Subject: [PATCH] fix paths to host app in non-root side folder --- service_worker.js | 6 +++--- src/effects.js | 2 +- src/index.js | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/service_worker.js b/service_worker.js index 3d230f7..a4a9579 100644 --- a/service_worker.js +++ b/service_worker.js @@ -30,12 +30,12 @@ self.addEventListener('message', async function(e) { }) // Fake directory, http requests to this directory intercepted by service_worker -const FILES_ROOT = '__leporello_files' +const FILES_ROOT = new URL('.', globalThis.location).pathname + '__leporello_files/' self.addEventListener("fetch", event => { const url = new URL(event.request.url) - if(url.pathname.startsWith('/' + FILES_ROOT)) { - const path = url.pathname.replace('/' + FILES_ROOT + '/', '') + if(url.pathname.startsWith(FILES_ROOT)) { + const path = url.pathname.replace(FILES_ROOT, '') let file diff --git a/src/effects.js b/src/effects.js index 3e29d47..459ae7a 100644 --- a/src/effects.js +++ b/src/effects.js @@ -32,7 +32,7 @@ const load_external_imports = async state => { // Note that we use the same origin as current page (where Leporello // is hosted), so Leporello can access window object for custom // `html_file` - window.location.origin + '/' + FILES_ROOT + '/' + u + FILES_ROOT + '/' + u )) ) const modules = Object.fromEntries( diff --git a/src/index.js b/src/index.js index 9688820..f2fd60e 100644 --- a/src/index.js +++ b/src/index.js @@ -8,8 +8,6 @@ const EXAMPLE = `const fib = n => : fib(n - 1) + fib(n - 2) fib(6)` -// Fake directory, http requests to this directory intercepted by service_worker -export const FILES_ROOT = '__leporello_files' const set_error_handler = (w, with_unhandled_rejection = true) => { // TODO err.message @@ -23,8 +21,11 @@ const set_error_handler = (w, with_unhandled_rejection = true) => { } } +// Fake directory, http requests to this directory intercepted by service_worker +export const FILES_ROOT = new URL('./__leporello_files', globalThis.location) + const get_html_url = state => { - const base = window.location.origin + '/' + FILES_ROOT + '/' + const base = FILES_ROOT + '/' return state.html_file == '' ? base + '__leporello_blank.html' : base + state.html_file + '?leporello'