DEV Community

voluntas
voluntas

Posted on

2

cowboy_static で application/wasm を返す

この記事は Cowboy を利用していて、 static で wasm ファイルを返したいが cowlib に用意されている mimetype にはデフォルトでは入っていないので、自前でやりたいというマニアックな内容です。

これは検証や開発向けで、そもそも本番では CDN や Nginx で返すべきです。

cowboy_static

cowboy_static には priv_file があるので、それを使います。
複数の wasm というのはここでは取り扱っていません。

  • test アプリケーションの priv/ に wasm.wasm が置いてある
  • URL は /test/wasm.wasm でアクセス
{"/test/wasm.wasm", cowboy_static,
 {priv_file, test, "wasm.wasm",
  [{mimetypes, {<<"application">>, <<"wasm">>, []}}]}},
Enter fullscreen mode Exit fullscreen mode

参考

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay