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
The error here appears to be a missing canonical_domain:
which is set in config/config.exs:
This suggests to me that HOST is not set correctly in the environment.
Also Liked
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],
axelson
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
Well what did ya know..I should def be reading more
. I appreciate the help! I got it up and running now!
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









