How can I get the "base url" of a Phoenix app?

Viewed 4062

When I run my Phoenix app locally, the base URL for all requests is something like http://localhost:4000. In production, it's something like https://example.com/.

I want to pass this base URL along to my JavaScript. How can I get it?

Note:

  • I don't want to check conn; this is something I want to set up during compilation or boot, not at request time.
  • I know I can check Application.get_env(:myapp, MyApp.Endpoint)[:url][:host] %, but that doesn't include the scheme (http or https) or the port. If I have to piece this together from several places, I probably can, but I'd rather not.
2 Answers
Related