The api Object & Host URL

21 views
Skip to first unread message

Paul Tiseo

unread,
Jun 29, 2015, 1:14:48 PM6/29/15
to action...@googlegroups.com
Is there a property in the api object (or elsewhere) that gives the host URL? I would like to create an email that would have a link in it, and want to be able to programmatically pull the host URL rather than hard-code it into a config file, such that when I run it localhost while coding, I send links with localhost, or use the appropriate URL when in production.

Michael Jensen

unread,
Jun 29, 2015, 1:52:22 PM6/29/15
to Paul Tiseo, action...@googlegroups.com
Hi Paul,

This is a tricky problem that I've seen a couple of times in the Rails world, basically it boils down to the fact that the most your app can find out is the IP address and port that it binds to on the server. The external (internet facing) address might be different, there might be proxies, CDNs, DDOS protection and all sorts between your server and the user. Of course, there is a "Host" header in each HTTP request (which you can read off the Connection object in an action), but it could be different in multiple requests!

The way I've solved this is to have configs that define the `asset host` and the `base url` of your site and just use those (asset host is for images you want to include in your emails).

Hope that helps!

On Mon, Jun 29, 2015 at 10:14 AM Paul Tiseo <paulx...@gmail.com> wrote:
Is there a property in the api object (or elsewhere) that gives the host URL? I would like to create an email that would have a link in it, and want to be able to programmatically pull the host URL rather than hard-code it into a config file, such that when I run it localhost while coding, I send links with localhost, or use the appropriate URL when in production.

--
You received this message because you are subscribed to the Google Groups "actionHero.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to actionhero-j...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Evan Tahler

unread,
Jun 29, 2015, 3:09:30 PM6/29/15
to action...@googlegroups.com, mje...@riotgames.com, paulx...@gmail.com
Yep, asset_host (and things like that) are common best-practices.  

There are even more problems with the host header, because you can spoof it, load balancers might modify it, etc.
To unsubscribe from this group and stop receiving emails from it, send an email to actionhero-js+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages