title: Serving static files in Cowboy (Erlang)
body: <p>I read this guide <a href="https://ninenines.eu/docs/en/cowboy/2.0/guide/static_files/" rel="nofollow noreferrer">https://ninenines.eu/docs/en/cowboy/2.0/guide/static_files/</a> and I implement</p>
  
  <p><code>{"/assets/[...]", cowboy_static, {dir, "/var/www/assets"}}</code></p>
  
  <p>in my <code>tunnel_app.erl</code> file:</p>
  
  <pre><code>-module(tunnel_app).
  -behaviour(application).
  
  -export([start/2]).
  -export([stop/1]).
  
  start(_Type, _Args) -&gt;
    Dispatch = cowboy_router:compile([
      {'_', [
      {"/info", lobby_handler, []},
      {"/join/:name", join_handler, []},
      {"/player/status/:name", player_status_handler, []},
      {"/tables/info/:table_id", table_info_handler, []},
      {"/tables/play/:table_id/:name/:auth/:action/:x/:y", table_play_handler, []},
      {"/assets/[...]", cowboy_static, {dir, "/static/assets"}}
      ]}]),
    {ok, _} = cowboy:start_clear(my_http_listener, 100,
      [{port, 8080}],
      #{env =&gt; #{dispatch =&gt; Dispatch}}),
    {ok, MainDoor} = door:go(),
    register(main_door, MainDoor),
    {ok, MainRoom} = room:go(),
    register(main_room, MainRoom),
    tunnel_sup:start_link().
  
  stop(_State) -&gt;
      ok.
  </code></pre>
  
  <p>I have my files in <code>static/assets</code>:</p>
  
  <pre><code>~/tunnel/ls static
  assets
  ~/tunnel/ls static/assets
  actions.js      dashboard.js        hole.js         player.js       tableview.js
  board.js        display.js      http.min.js     script.js       tile.js
  callback.js     engine.js       info.js         style.css       view.js
  client.js       engine_client.js    moves           table.js
  clock.js        game.html       notes           tablemaster.js
  color.js        ground.js       oboard.js       tableproxy.js
  ~/tunnel/
  </code></pre>
  
  <p>When I navigate to</p>
  
  <p><code>http://localhost:8080/assets/game.html</code></p>
  
  <p>My browser gets a 404.</p>
  
  <p>EDIT:</p>
  
  <p>The root path of the project is <code>/users/quantum/tunnel</code> with <code>/users/quantum/tunnel/src</code> being where all the `.erl files live.</p>
  
  <p>I tried changing the path to <code>"{"/assets/[...]", cowboy_static, {dir, "/users/quantum/tunnel/src/static/assets/"}}"</code></p>
  
  <p>and navigating to <code>localhost:8080/assets/game.html</code> shows nothing (not even 404)</p>
  
  <p>Aha! I made a mistake in the path - static is in the root of the project, not inside src.</p>
  
  <p><code>{"/assets/[...]", cowboy_static, {dir, "../static/assets/"}}</code> does not work nor does <code>static/assets</code>, however:</p>
  
  <p><code>{"/assets/[...]", cowboy_static, {dir, "/users/quantum/tunnel/static/assets/"}}</code> does work.</p>