I have an application with a sitemap.xml. I need to modify it dynamically once a day. In production environment.
I know how to generate the content for it. But how can I actually replace(!) my current sitempa.xml with a new generated one, or rather its content? If it was a rails app, I’d merely replace its content and it’ll work, but for phoenix it’s different because it’s somehow compiled, right?
My code for serving sitemap.xml is the standard one:
defmodule MyApp.Endpoint do
# ................
# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phoenix.digest
# when deploying your static files in production.
plug Plug.Static,
at: "/", from: :my_app, gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt sitemap.xml)
Should I create a special route/action for “sitemap.xml” and serve it in a controller?
If you are behind a reverse proxy, just generate the file and put it to a place where your RP can find and serve it before handing the request over to you. This is what I’d prefer for all static and semi-static resources
Let Phoenix handle the generation of the data. Generate it once a day and put it into temporal storage on diosk or database and serve it from there.
(this is the half one) Generate the data on each request. If you can do this quickly just do this for the sake of simplicity, if though generating the sitemap is costly, try to do one of the other points first!