fix paths to host app in non-root side folder

This commit is contained in:
Dmitry Vasilev
2023-01-18 16:30:44 +08:00
parent 9a6b700086
commit 25044547d6
3 changed files with 8 additions and 7 deletions

View File

@@ -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

2
src/effects.js vendored
View File

@@ -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(

View File

@@ -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'