Trying to serve a wasm file as a static asset from phoenix (cowboy) but need to set my content-type

As the title says, I’m trying to serve a static asset from Phoenix/Cowboy for local development but hitting a little snag as there is currently no mime type for wasm

The result is I get this console error while trying to load the wasm file.

Uncaught (in promise) TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'

The current content type I’m getting is content-type: application/octet-stream.

My question is how would if I can set this myself for the time being from phoenix, assume I can as I expect this to be an issue with cowboy?

Use the :content_types option for Plug.Static:

:content_types - custom MIME type mapping. As a map with filename as key and content type as value. For example: content_types: %{"apple-app-site-association" => "application/json"} .

1 Like