stoiven

stoiven

Assets not loading when deploying to Heroku

Hi there! I have deployed this (after forking) to Heroku, but for some reason, none of the assets are loading. I’m fairly new to the language and I have a feeling that maybe some environmental variable might be misconfigured or something?

The front page loads perfectly fine, but not as intended. I went to check the developer tools and realized that it was doing a GET call from localhost, which I don’t believe is right?

GET http://localhost:43751/css/app-b358ab485f4965187a0366829058b5e7.css?vsn=d net::ERR_CONNECTION_REFUSED

GET http://localhost:43751/js/app-47ffdb6029e02e02cf2f5c4f4e2c7e4e.js?vsn=d net::ERR_CONNECTION_REFUSED

localhost:43751/images/til-logo-144x144-866373717b4dc8f05b886baaf7abae3b.png?vsn=d:1 

GET http://localhost:43751/images/til-logo-144x144-866373717b4dc8f05b886baaf7abae3b.png?vsn=d net::ERR_CONNECTION_REFUSED

Error while trying to use the following icon from the Manifest: http://localhost:43751/images/til-logo-144x144-866373717b4dc8f05b886baaf7abae3b.png?vsn=d (Download error or resource isn't a valid image)

Not sure if the config needs to be changed here: tilex/config/config.exs at master · hashrocket/tilex · GitHub since this is where I find localhost only existing or if it needs to be added to the Heroku config vars, but I have inputted in the SECRET_KEY_BASE on Heroku.

The dyno is using: web MIX_ENV=prod mix phx.server and made sure it’s pointing to my app.
Sorry if I’m not providing all the information needed, so please let me know if I’m missing something.

Marked As Solved

al2o3cr

al2o3cr

The error here appears to be a missing canonical_domain:

https://github.com/hashrocket/tilex/blob/8f5fc50d9e12fd0cd409e54c7b135dac8ef4e7f4/lib/tilex_web/controllers/post_controller.ex#L213-L217

which is set in config/config.exs:

https://github.com/hashrocket/tilex/blob/8f5fc50d9e12fd0cd409e54c7b135dac8ef4e7f4/config/config.exs#L28

This suggests to me that HOST is not set correctly in the environment.

Also Liked

wmnnd

wmnnd

Hey there!

Just a quick note: Usually people prefer building a Release first and deploying that instead of installing Elixir and mix and then using mix phx.server. Check out the docs on Releases here:
https://elixir-lang.org/getting-started/mix-otp/config-and-releases.html

To address your immediate issue, did you make sure to a) install and build your assets (npm run deploy --prefix ./assets) and b) compile your assets with mix phx.digest?

I also recommend you take a look at the Deployment Guide from Phoenix:

In case the issue is actually related to the generation of absolute URLs: You might have to change the URL configuration from

config :tilex, TilexWeb.Endpoint,
  url: [host: "localhost"],

to something like

config :tilex, TilexWeb.Endpoint,
  url: [host: "example.com", scheme: :https],

(see Phoenix.Endpoint — Phoenix v1.8.8)

axelson

axelson

Scenic Core Team

Generally I would probably write this something more like:

base = System.get_env("EDGE_URL") || System.get_env("HOST") || "https://stoiven-til.herokuapp.com"
static_url =
  URI.parse(base)
  |> Map.from_struct()

But calling Map.from_struct on a %URI{} seems highly atypical. Usually I would call to_string on the %URI{} to get out a plan URL (e.g. "https://stoiven-til.herokuapp.com"), but if you wanted that in this case you would not even need URI.parse unless you’re using it for validation. Can you show how you’re using static_url?

For the other issues I think you should post a new topic, and make sure to include the implementation of the controllers (along with the exceptions).

stoiven

stoiven

Well what did ya know..I should def be reading more :sweat_smile:. I appreciate the help! I got it up and running now!

Where Next?

Popular in Questions Top

albydarned
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
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
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
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
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
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
shijith.k
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
yawaramin
In the Dialyzer docs ( dialyzer — OTP 29.0.2 (dialyzer 6.0.1) ), there is a way to turn off a specific warning for a function: -dialyzer...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
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
albydarned
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
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
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
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement