MarkMekhaiel

MarkMekhaiel

Serving static files from a phoenix API

I’m trying to serve a file from my phoenix API, and believe Plug.Static is the way to do it, but am struggling to get it to work.

The file is an apple certificate, and I’m placing it in priv/certificates/apple

I’ve setup the following code in my endpoint.ex file:

plug Plug.Static,
    at: "/.well-known/apple",
    from: :my_app,
    gzip: false,
    only: ~w(certificates apple)

But when I visit the URL I get no route found for GET /.well-known/apple.

Do I need to add this to my routes file? And if so, does it hit a controller? What would that controller action look like?

Thanks in advance

Marked As Solved

stefanchrobot

stefanchrobot

The default path for reading static files is priv/static, so you need to tweak it:

plug Plug.Static,
    # Note the root path.
    at: "/.well-known",
    from: {:my_app, "priv/certificates"},
    gzip: false,
    only: ~w(apple)

But I’d suggest following @silverdr advice and put the files in the usual location. Assuming the actual file is called apple, try this:

  • Put the file into static: /priv/static/.well-known/apple
  • Use “standard” Static plug config:
  plug Plug.Static,
    at: "/",
    from: :my_app,
    gzip: false,
    only: [".well-known"]

Also Liked

silverdr

silverdr

How about simply putting it in priv/static/...?

Last Post!

dimitarvp

dimitarvp

You could post your relevant router config and maybe somebody else can chime in?

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36689 110
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement