zimt28

zimt28

Phoenix doesn't serve static files

Hi there,

I just managed to deploy my first Phoenix app using edeliver. The only problem left are static files, which Phoenix doesn’t serve right now: When I try to access /css/app.css, I get Phoenix 404 page.

I’ve added the following to my .deliver/config file:


pre_erlang_clean_compile() {
    status "Running phoenix.digest" # log output prepended with "----->"
    __sync_remote " # runs the commands on the build host
      [ -f ~/.profile ] && source ~/.profile # load profile (optional)
      set -e # fail if any command fails (recommended)
      cd '$BUILD_AT' # enter the build directory on the build host (required)
      # prepare something
      mkdir -p priv/static # required by the phoenix.digest task
      # run your custom task
      APP='$APP' MIX_ENV='$TARGET_MIX_ENV' $MIX_CMD phoenix.digest $SILENCE
    "
  }

In my config/prod.exs file, I’ve got the following configuration:

# (PORT is "80" and URL is the server's IP)
config :app, App.Endpoint,
  http: [port: {:system, "PORT"}],
  url: [host: {:system, "URL"}, port: 80],
  cache_static_manifest: "priv/static/manifest.json"

config :app, App.Endpoint, root: "."

When I run mix phoenix.digest and MIX_ENV=prod mix release --prod locally, phoenix serves my static files though.

EDIT: On my build server, /tmp/edeliver/app/builds/priv only contains a manifest.json file, which again just consists of an empty object {}. The static files do exist inside of /tmp/edeliver/app/builds/web/static.

EDIT 2: I’ve changed the last line of my .deliver/config file to the following:

APP='$APP' MIX_ENV='$TARGET_MIX_ENV' $MIX_CMD phoenix.digest web/static -o priv/static $SILENCE

The mix phoenix.digest thing seems to work now, but I have to run brunch before somehow. How can I do that?

Marked As Solved

zimt28

zimt28

All right, looks like I found a working solution. Just in case someone has similar problem, here’s a .deliver/config file, that works for me:

#!/usr/bin/env bash

APP="app"

BUILD_HOST="123.45.67.8"
BUILD_USER="root"
BUILD_AT="/tmp/edeliver/app/builds"

STAGING_HOSTS="123.45.67.8"
STAGING_USER="root"
DELIVER_TO="/home/web"

pre_erlang_get_and_update_deps() {
  local _prod_secret_path="/home/builder/prod.secret.exs"
  if [ "$TARGET_MIX_ENV" = "prod" ]; then
    __sync_remote "
      ln -sfn '$_prod_secret_path' '$BUILD_AT/config/prod.secret.exs'
    "
  fi
}

pre_erlang_clean_compile() {
    status "Installing NPM dependencies"
    __sync_remote "  # runs the commands on the build host
      [ -f ~/.profile ] && source ~/.profile # load profile
      set -e # fail if any command fails

      cd '$BUILD_AT' # go to the build directory on the build host
      npm install $SILENCE
    "

    status "Building static files"
    __sync_remote "
      [ -f ~/.profile ]
      set -e

      cd '$BUILD_AT'
      mkdir -p priv/static
      npm run deploy $SILENCE
    "

    status "Running phoenix.digest"
    __sync_remote "
      [ -f ~/.profile ] && source ~/.profile
      set -e

      cd '$BUILD_AT'
      APP='$APP' MIX_ENV='$TARGET_MIX_ENV' $MIX_CMD phoenix.digest $SILENCE
    "
  }

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
greenz1
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
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
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
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement