Serving .well-known/apple-app-site-association Works in Development env but returns Phoenix.HTML.Safe error in Release

Hi all, in my umbrella app I’ve added this to my endpoint.ex file right after the “/” static plug:

  plug Plug.Static,
    at: "/.well-known",
    from: {:faithful_word_api, "priv/static/well-known"},
    gzip: false,
    content_types: %{"apple-app-site-association" => "application/json"}

serves fine with this url locally: http://localhost:4000/.well-known/apple-app-site-association

but after deploying with a multi-stage docker release on a digital ocean vps(with http-> https routing performed by Traefik, behind cloudflare), the path results with this in the log:

faithful_word_umbrella    | 13:30:39.055 [error] #PID<0.6413.0> running FaithfulWordApi.Endpoint (connection #PID<0.6409.0>, stream id 3) terminated
faithful_word_umbrella    | Server: (http)
faithful_word_umbrella    | Request: GET /.well-known/apple-app-site-association
faithful_word_umbrella    | ** (exit) an exception was raised:
faithful_word_umbrella    |     ** (Protocol.UndefinedError) protocol Phoenix.HTML.Safe not implemented for %{error: "unexpected"} of type Map. This protocol is implemented for the following type(s): Decimal, BitString, Atom, Float, Date, Time, Phoenix.HTML.Form, Integer, List, Tuple, DateTime, NaiveDateTime
faithful_word_umbrella    |         (phoenix_html) lib/phoenix_html/safe.ex:1: Phoenix.HTML.Safe.impl_for!/1
faithful_word_umbrella    |         (phoenix_html) lib/phoenix_html/safe.ex:15: Phoenix.HTML.Safe.to_iodata/1
faithful_word_umbrella    |         (phoenix) lib/phoenix/controller.ex:729: Phoenix.Controller.__put_render__/5
faithful_word_umbrella    |         (phoenix) lib/phoenix/endpoint/render_errors.ex:77: Phoenix.Endpoint.RenderErrors.instrument_render_and_send/5
faithful_word_umbrella    |         (phoenix) lib/phoenix/endpoint/render_errors.ex:62: Phoenix.Endpoint.RenderErrors.__catch__/5
faithful_word_umbrella    |         (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4
faithful_word_umbrella    |         (cowboy) /app/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
faithful_word_umbrella    |         (cowboy) /app/deps/cowboy/src/cowboy_stream_h.erl:296: :cowboy_stream_h.execute/3

I checked the paths also:

root@edge-faithful-word:~/faithfulword-phx/apps/faithful_word_api/priv/static/well-known# ll
total 16
drwxr-xr-x 2 root root   4096 Feb  9 12:59 ./
drwxr-xr-x 3 root root   4096 Feb  9 12:59 ../
-rw-r--r-- 1 root docker  255 Feb  9 12:59 apple-app-site-association
-rw-r--r-- 1 root docker  292 Feb  9 12:59 assetlinks.json

The only thing that looks bogus to me is the docker group ownership but not sure this matters because the permissions appear to be world readable.

Any other ideas? Deploying with Elixir 1.9.4(alpine). I happen to be using 1.10.0 in the dev env.

There are two errors happening. The request is failing but when rendering the error page, another error bubbles up. So my impression is that your 500 pages are also broken. I would suggest to set debug_errors: false in dev, check and fix the error pages, and then find out what is the actual underlying issue.

1 Like

Thanks yeah the error-catching was fully broken. But I fixed it all and I was actually getting a 404 in prod(I believe because I was placing the files in priv/static, which dev could find but not prod … could be a copydir issue while building the release docker image, not sure yet).

I’m getting the files now but I have to place them in assets/static and I manually added the literal names in the only: clause in the plug in endpoint.ex:

  plug Plug.Static,
    at: "/",
    from: :faithful_word_api,
    gzip: false,
    only: ~w(css fonts images js favicon.ico robots.txt apple-app-site-association assetlinks.json)

(not using .well-known at the moment, apparently you can optionally place them at webroot).
Thanks for putting me in the right direction.

I finally settled on this configuration:

  plug Plug.Static,
    at: "/",
    from: :faithful_word_api,
    gzip: false,
    only: ~w(css fonts images js favicon.ico robots.txt .well-known)

and I git -f force-added the files in assets/static/.well-known:

git add -f .well-known/

new file:   .well-known/apple-app-site-association
new file:   .well-known/assetlinks.json

works fine in both dev and prod.

when deployed, test with