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
I would like to know what is the best IDE for elixir development?
New
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
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
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
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









