How to discover the *external* hostname from within a heroku cedar application - heroku

I am deploying a RubyOnRails 3.1 app to heroku cedar stack. From within the app I would like to auto discover the host name (i.e. appname.herokuapp.com). I have multiple deployments of the same app on heroku - some for development, some for staging and some for production. It would be nice to be able to check an environment variable or make some call to find out my app host name from within the app.

does
request.host
give you want you want?

Related

How to Provision APIs on Heroku

Please forgive my question. I am a complete newbie at this.
I have built an API in spring boot and I have pushed it to heroku.
I have a custom domain for my website already as www.mywebsite.com
I want to provision my apis under this domain as well as api.mywebsite.com
How can I achieve this on heroku?
Any help on how to go about this would be sincerely appreciated.
Thanks
I will assume that you have full access to the Namecheap account.
You have 2 options:
A. Use Heroku CLI
B. Use Heroku interface (Web application)
A) Let's go through the process with Heroku CLI.
Make sure that you have the Heroku CLI installed (macOS: brew install heroku, Ubuntu: apt install heroku, etc.)
Add your domain using the command heroku domains:add api.website.com (if you have multiple apps, don't forget at the end of the command to add --app name-of-your-heroku-app.
Heroku will generate for you a DNS target for the custom domain you added at step 2. Run heroku domains and copy the DNS target (The DNS target looks like this: whispering-willow-5678.herokudns.com)
Open your Namecheap domain settings and add a CNAME (Name: "api" and Target: the DNS target provided by Heroku).
Wait few minutes up to few hours.
B) If you want to use Heroku Interface / Webapplications.
Open your app on www.herokuapp.com
Go to "Settings" tab
Scroll down to "Domains"
Click on "Add domains"
Add your subdomain (api.website.com)
Heroku will generate for you a DNS Target
Navigate to your domain settings in Namecheap and create a new CNAME using your subdomain (e.g. api) as name and the DNS target provided by Heroku as target.
You can find all the details in Custom Domain Names for Apps Heroku Documentation

How can I setup and deploy a database with Deis (PaaS)

I'm trying to setup a database with Deis. I know this is possible, but there doesn't seem to be any documentation about how to do it other than setting an ENV variable.How could I setup say a MongoDB or Cassandra docker container and then deploy that and have my deis app use it?
If you're trying to deploy now, a possible solution is to set up a docker container, have it publicly route-able, and then configure your application to use that container through an environment variable following Heroku's 12 factor app best practices. There is a feature request for a Deis service gateway that will act like Heroku's Add-on Marketplace, but it's not there yet.

Multiple heroku applications for the same local application

I have one application at my local machine and it's deployed to heroku. Or I must say, I was deployed - only a landing page. I have its own domain (example.com). However, it's in a test phase now and I want to deploy it to demo.example.com. I've already created another application for this at heroku (demo-example-com).
I could create a new local copy specially for demo-example-com but I don't think it's sensible. Instead I want to push the same local application to the different heroku applicaions (not accounts): example.com and demo-example-com.
How do I do this if this is possible?
Heroku has good documentation on how to deploy to multiple environments from your local machine. In other words, how to push to different applications in the same account from one local repository. See https://devcenter.heroku.com/articles/multiple-environments.

heroku subdomain wildcard on herokuapp.com

I am running a PHP application on Heroku and am wondering if I can have wildcard subdomains on top of the herokuapp.com hosted subdomain. For example I have my application running on mysubdomain.herokuapp.com through Heroku, however can I make it so *.mysubdomain.herokuapp.com points still to my server?
I am simply uploading my PHP application to the heroku instance by using 'git push heroku master'
unfortunately what you are trying to achieve is not feasible

Is it possible to whitelist Heroku apps?

I have a Heroku application that binds with a telco sms gateway via SMPP
The telco guys need to whitelist IPs for my app to connect.
I am aware of the new addon proximo, but it's just insanely priced. So that option is out.
Is there a subnet or a list of IPs that I can get whitelisted and is there a guarantee that all requests from my app will originate from tose IPs?
I found this https://api.heroku.com/vendor/logplex/allowlist.
Is that only for syslog or all apps make a request from one of those IPs?
Thanks
There is now a Heroku add-on that does this called Proximo: https://addons.heroku.com/proximo
The Heroku docs specifically mention how dynos don't have static IP addresses. Even when using custom domains it looks like they want you to point to a CNAME record rather than an IP address. So if you need a static IP it looks like Proximo is your best bet.
Would it be possible to use an API token to authenticate your app with the sms gateway, similar to the way the blitz.ip plugin works with heroku? Then you might not need to use a static IP whitelist.
This question looks to be doing something similar to you, and this answer suggests using a hosted VPN service. Would that work?
Heroku now has Private Spaces which is what you are looking for:
https://www.heroku.com/private-spaces
Another Heroku addon option is Quotaguard , in beta, free for now.
Answering my own question. Even though an external VPN or the proximo addon are a solution in case you want to whitelist a Heroku app, I have decided to go for the simpler option and host the SMPP binding service of my app on ec2 using an Elastic IP
You can host a proxy yourself using Dockhero Heroku add-on - https://dockhero.io/ - which has a static IP (AWS elastic IP).
Install the add-on and the CLI plugin:
$ heroku addons:create dockhero
$ heroku plugins:install dockhero
Wait until the provisioning is done and get DOCKHERO_HOST environment variable
$ heroku dh:wait
$ heroku config:get DOCKHERO_HOST
--> e.g. dockhero-spherical-42047.dockhero.io
Create dockhero-compose.yml file with the following contents:
version: "2"
services:
proxy:
image: tecnativa/tcp-proxy
environment:
LISTEN: ":80"
TALK: "www.wikipedia.org:80"
ports:
- "80:80"
Here www.wikipedia.org:80 is the server which you build a proxy for.
Find more about the syntax in https://docs.docker.com/compose/compose-file/compose-file-v2/
Run this stack in the cloud using Dockhero CLI:
$ heroku dh:compose up -d
Any requests to the host from DOCKHERO_HOST Heroku config var will now be proxied according to your dockhero-compose.yml
$ curl http://dockhero-spherical-42047.dockhero.io/
--> <response from www.wikipedia.org>
IMPORTANT: as of writing this, dockhero.io is in Beta and available for free. When switching to production, the assigned IP may be changed after a prior notification.
Fixie is another alternative add-on not mentioned here. Free plan with 500 requests per month. Requires some adjustments in code and heroku app to be in us region (or you can migrate it: Migrating an Application to Another Region). Worked for me.

Resources