Search code examples
routeselixirassetsphoenix-framework

Serving Static TXT Files from Phoenix


I need to serve a Static TXT file from my Phoenix app, for domain verification purposes:

• Google Search Console

• GoGetSSL certification

Both companies asked me to upload, each a different TXT file that would be verified on the root path of my domain.

Like so: http://example.com/091823091231902322389.txt

I downloaded the TXT file and have placed it into the web/static/assets folder.

But when trying to reach it using the browser I obviously get a no route found for GET

How can I make sure files within the web/static/assets folder are served by Phoenix?


Solution

  • After adding the file to web/static/assets, you also need to add the filename to the Plug.Static whitelist. In your lib/my_app/endpoint.ex, change:

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

    to

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