fix: Calculate upload path at runtime

This commit is contained in:
Ro 2024-10-26 16:54:35 -05:00
parent 3959deb503
commit b83d818ce5
Signed by: ro
GPG key ID: 5B5AD5A568CDABF9
3 changed files with 11 additions and 13 deletions

View file

@ -11,16 +11,6 @@ config :postland,
ecto_repos: [Postland.Repo], ecto_repos: [Postland.Repo],
generators: [timestamp_type: :utc_datetime] generators: [timestamp_type: :utc_datetime]
upload_path =
if config_env() == :prod do
System.get_env("DATABASE_PATH") |> Path.dirname() |> Path.join("uploads/")
else
File.cwd!() |> Path.join("uploads/")
end
config :postland,
upload_path: upload_path
# Configures the endpoint # Configures the endpoint
config :postland, PostlandWeb.Endpoint, config :postland, PostlandWeb.Endpoint,
url: [host: "localhost"], url: [host: "localhost"],

View file

@ -20,6 +20,16 @@ if System.get_env("PHX_SERVER") do
config :postland, PostlandWeb.Endpoint, server: true config :postland, PostlandWeb.Endpoint, server: true
end end
upload_path =
if config_env() == :prod do
System.get_env("DATABASE_PATH") |> Path.dirname() |> Path.join("uploads/")
else
File.cwd!() |> Path.join("uploads/")
end
config :postland,
upload_path: upload_path
if config_env() == :prod do if config_env() == :prod do
database_path = database_path =
System.get_env("DATABASE_PATH") || System.get_env("DATABASE_PATH") ||

View file

@ -27,11 +27,9 @@ defmodule PostlandWeb.Endpoint do
gzip: false, gzip: false,
only: PostlandWeb.static_paths() only: PostlandWeb.static_paths()
Logger.info("File upload path: #{Postland.Uploads.upload_path()}")
plug Plug.Static, plug Plug.Static,
at: "/uploads", at: "/uploads",
from: Postland.Uploads.upload_path(), from: {Postland.Uploads, :upload_path, []},
gzip: false gzip: false
# Code reloading can be explicitly enabled under the # Code reloading can be explicitly enabled under the