From 01e61cec657e3d7aca555442d0e54c8a67f87be1 Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Mon, 10 Jun 2024 01:29:52 +0900 Subject: [PATCH] Consider base href on the web --- flutter_ffi_plugin/lib/src/load_web.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/flutter_ffi_plugin/lib/src/load_web.dart b/flutter_ffi_plugin/lib/src/load_web.dart index 759492a2..a4861d5b 100644 --- a/flutter_ffi_plugin/lib/src/load_web.dart +++ b/flutter_ffi_plugin/lib/src/load_web.dart @@ -23,13 +23,19 @@ Future loadJsFile() async { final loadCompleter = Completer(); js.context['completeRinfLoad'] = loadCompleter.complete; + // Flutter app doesn't always have the top-level path of the domain. + // Sometimes, the flutter app might be placed in a lower path. + // This variable includes domain and the base path. + final baseHref = Uri.base; + // Use the default JavaScript path unless provided. - final path = jsLibPath ?? "/pkg/hub.js"; + final path = jsLibPath ?? "pkg/hub.js"; + final fullUrl = baseHref.resolve(path); final scriptElement = ScriptElement(); scriptElement.type = "module"; scriptElement.innerHtml = ''' -import init, * as wasmBindings from "$path"; +import init, * as wasmBindings from "$fullUrl"; await init(); window.rinf = { ...wasmBindings }; completeRinfLoad();