Skip to content

Commit

Permalink
Merge pull request #364 from cunarist/base-href
Browse files Browse the repository at this point in the history
Consider base href on the web
  • Loading branch information
temeddix committed Jun 9, 2024
2 parents c813f51 + 01e61ce commit 5d63209
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions flutter_ffi_plugin/lib/src/load_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ Future<void> loadJsFile() async {
final loadCompleter = Completer<void>();
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();
Expand Down

0 comments on commit 5d63209

Please sign in to comment.