container2wasm icon indicating copy to clipboard operation
container2wasm copied to clipboard

Instructions for hosting locally (from a directory)

Open pmmccorm opened this issue 1 year ago • 8 comments

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?

pmmccorm avatar Jan 15 '24 20:01 pmmccorm

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.

ktock avatar Jan 16 '24 01:01 ktock

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.

coder0107git avatar Jan 16 '24 05:01 coder0107git

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

pmmccorm avatar Jan 17 '24 23:01 pmmccorm

It seems close but I get a strange error.

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

Error: image

pmmccorm avatar Feb 21 '24 22:02 pmmccorm

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);
    });
}

pmmccorm avatar Feb 21 '24 22:02 pmmccorm

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

ktock avatar Feb 22 '24 02:02 ktock

You mean the out.wasm?

pmmccorm avatar Feb 22 '24 17:02 pmmccorm

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/

pmmccorm avatar Feb 22 '24 17:02 pmmccorm