ring icon indicating copy to clipboard operation
ring copied to clipboard

how to add wasm(WebAssembly)and etc content-type?

Open PlumpMath opened this issue 4 years ago • 5 comments
trafficstars

I'm using ring.middleware.cors with unity3d wasm.

error: wasm streaming compile failed: TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.

warning: HTTP Response Header "Content-Type" configured incorrectly on the server for file Build/MyGame.wasm , should be "application/wasm". Startup time performance will suffer.

(def ring-middle (-> ROUTE/my-route RING-MIDDLEWARE-JSON/wrap-json-body RING-MIDDLEWARE-JSON/wrap-json-response (RING-MIDDLEWARE-DEFAULTS/wrap-defaults RING-MIDDLEWARE-DEFAULTS/site-defaults) (RING-MIDDLEWARE-CORS/wrap-cors :access-control-allow-credentials "true" :access-control-allow-origin [#".*"] :access-control-allow-headers #{"accept" "accept-encoding" "accept-language" "authorization" "content-type" "origin"} ;; I want to add mime-types. "content-type:... "application/wasm br gz javascript" ... etc :access-control-allow-methods [:get :put :post :delete :options]) ))

PlumpMath avatar Nov 02 '21 14:11 PlumpMath

Take a look at the ring.middleware.content-type/wrap-content-type middleware function. You can customize it by supplying your own mimetype map.

weavejester avatar Nov 02 '21 15:11 weavejester

Thanks for the hint. But it doesn't work. When loading js from the html side, the address… Do I have to wrap the route by pulling out unity in advance? And when I go to the map and set content-type as the key and application/wasm as the value, the result is the same. The webgl page itself doesn't use index.html but loads unity webgl js from hiccup so I'm not sure what to do anymore. So I wonder if this suspicion is correct... (Actually, the program runs without problems. I just want to make sure I catch errors and warnings.)

PlumpMath avatar Nov 05 '21 07:11 PlumpMath

Can you show me what you're doing when you say it doesn't work?

Also, how are you serving the wasm files? I assume as a public resource?

weavejester avatar Nov 05 '21 11:11 weavejester

I can't upload the project as it is because will work, so I'll make a simple example and upload it. Please understand that it may be late. thank you.

PlumpMath avatar Nov 05 '21 22:11 PlumpMath

It's so late, I'm sorry. work is too busy; I was busy with other things.

After a few months of work end it, and as soon as possible I was thinking of uploading example at this rest time.

For Unity webgl compilation, there are two ways to compress wasm once (br and gzip method). This is an uncompressed build.

Please take a look, and I hope you catch the error by adding content-type: . thank you. @weavejester

PlumpMath avatar Mar 04 '22 11:03 PlumpMath

I've been waiting for you to upload the example. There doesn't seem to be one linked or attached to the issue.

weavejester avatar Aug 20 '22 11:08 weavejester

hmm i'm solve! sorry~. ;;

unity webgl build gzip & compression fallback? (check) That way I don't have to deal with it.

And I'm not sure if this has any effect... https://gist.github.com/martintrojer/841d6712a432380fe97c

Later, not unity wasm, other c++ or rust or godot (tools I want to deal with) If a problem occurs in ... (I hope do not think again, but the web is too difficult for me...) thank you

PlumpMath avatar Aug 21 '22 14:08 PlumpMath