title: How can I get the "base url" of a Phoenix app?
body: <p>When I run my Phoenix app locally, the base URL for all requests is something like <code>http://localhost:4000</code>. In production, it's something like <code>https://example.com/</code>.</p>
  
  <p>I want to pass this base URL along to my JavaScript. How can I get it?</p>
  
  <p>Note:</p>
  
  <ul>
  <li>I don't want to check <code>conn</code>; this is something I want to set up during compilation or boot, not at request time.</li>
  <li>I know I can check <code>Application.get_env(:myapp, MyApp.Endpoint)[:url][:host] %</code>, but that doesn't include the scheme (<code>http</code> or <code>https</code>) or the port. If I have to piece this together from several places, I probably can, but I'd rather not.</li>
  </ul>