HomeForumSourceResearchGuide
Sign in to reply to forum posts.
Serving WebAssembly from ws.core applications

Hello,

I've been playing with the new WebAssembly build of Dana (so cool by the way!). I'm using it with ws.core as the web-server but I would like to be able to serve the WASM elements dynamically from get() requests. The readme for the WASM SDK only contains a solution for static content via the xdata.html file. I've had a look at the HTML in that file and tried to serve it from a get() but it seems not to load with some web assembly exception in the browser log:

The WebAssembly.Memory object cannot be serialized.

I guess there's something obvious that I'm missing here but I'm not sure what? :)

jess

Hi jess,

You need to set some headers related to security. Before you send any data do the following, where s is your DocStream instance:

s.setHeaders(new Header[](new Header("Cross-Origin-Embedder-Policy", "require-corp"),
                        new Header("Cross-Origin-Opener-Policy", "same-origin"),
                        new Header("content-type", "text/html")))

In the WASM SDK we've done this for static content via the ws config file. The ws framework does not apply headers for dynamic content via get()/post(), though, so you need to do it yourself as above.

I've also added a content-type header, since some browsers require this to load WASM modules.

Barry

Ah that worked thank you! :)

jess