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
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”
Staticplug config:
plug Plug.Static,
at: "/",
from: :my_app,
gzip: false,
only: [".well-known"]
2
Also Liked
silverdr
Last Post!
dimitarvp
Popular in Questions
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
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
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
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
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
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
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
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
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
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
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









