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

Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
ovidiubadita
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
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New

Other popular topics Top

pmjoe
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
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement