ktock / container2wasm

Container to WASM converter
https://ktock.github.io/container2wasm-demo/
Apache License 2.0
2.03k stars 80 forks source link

Instructions for hosting locally (from a directory) #211

Open pmmccorm opened 9 months ago

pmmccorm commented 9 months ago

Hello I think it would be very useful to post how to host the containers locally (from a directory, ie file://...).

Without all the docker running httpd stuff.

Is this possible?

ktock commented 9 months ago

Our example currently requires HTTP headers for using SharedArrayBuffer https://github.com/ktock/container2wasm/blob/b3e4d9253eb710ddebc2962494964477d2458e44/examples/wasi-browser/xterm-pty.conf If we can avoid using that, loading pages from local file will be possible.

coder0107git commented 9 months ago

Something like this might be helpful. I don't know how well it would work from a file url but it does work well with stuff like Github Pages.

pmmccorm commented 9 months ago

Ah I think that is what I am looking for. Thank you. Maybe an example that can be hosted from GH pages?

pmmccorm commented 8 months ago

It seems close but I get a strange error.

See: https://pmmccorm.github.io/container_on_browser/index.html

Error: image

pmmccorm commented 8 months ago

Which might be this bit from worker.js:

function startWasi(wasm, ttyClient, args, env, fds, listenfd, connfd) {
    var wasi = new WASI(args, env, fds);
    wasiHack(wasi, ttyClient, connfd);
    wasiHackSocket(wasi, listenfd, connfd);
    WebAssembly.instantiate(wasm, {
        "wasi_snapshot_preview1": wasi.wasiImport,
    }).then((inst) => {
        wasi.start(inst.instance);
    });
}
ktock commented 8 months ago

Could you check you specified the correct URL for the wasm file in your script?

pmmccorm commented 8 months ago

You mean the out.wasm?

pmmccorm commented 8 months ago

Aha! That did it. When I host on github pages it appears that:

location.origin

Is pointing to the top domain, but it needs to go to: location.origin + /gh_repo_name/