Skip to content

Commit

Permalink
Allow the page's query parameters to tweak which package wasmer.sh wi…
Browse files Browse the repository at this point in the history
…ll run
  • Loading branch information
Michael-F-Bryan committed Jan 4, 2024
1 parent a381115 commit e5f39a7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions examples/wasmer.sh/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { Terminal } from "xterm";
import { FitAddon } from "xterm-addon-fit";

const encoder = new TextEncoder();
const params = new URLSearchParams(window.location.search);

const packageName = params.get("package") || "sharrattj/bash";
const uses = params.getAll("use");
const args = params.getAll("arg");
const logFilter = params.get("log") || "warn";

async function main() {
// Note: We dynamically import the Wasmer SDK to make sure the bundler puts
Expand All @@ -18,7 +23,7 @@ async function main() {
const { Wasmer, init, initializeLogger } = await import("@wasmer/sdk");

await init(wasmerSDKUrl);
// initializeLogger("debug");
initializeLogger(logFilter);

const term = new Terminal({ cursorBlink: true, convertEol: true });
const fit = new FitAddon();
Expand All @@ -27,9 +32,9 @@ async function main() {
fit.fit();

term.writeln("Starting...");
const pkg = await Wasmer.fromRegistry("sharrattj/bash");
const pkg = await Wasmer.fromRegistry(packageName);
term.reset();
const instance = await pkg.entrypoint!.run();
const instance = await pkg.entrypoint!.run({ args, uses });
connectStreams(instance, term);
}

Expand Down

0 comments on commit e5f39a7

Please sign in to comment.