How do I connect my microservice deployed on heroku - heroku

I have two microservice (using nest.js) deployed on heroku. When I try to connect I get this error:
Error: getaddrinfo ENOTFOUND https://URL.herokuapp.com
This is the my way for connect to microsrevice.
{
imports: [ConfigModule],
inject: [ConfigService],
name: 'CURRENCY_SERVICE',
useFactory: (configService: ConfigService) => {
return {
transport: Transport.TCP,
options: {
host: configService.services.currency.host,
port: configService.services.currency.port,
},
}
},
}
I couldn't find the port number heroku assign. So I just log the port number after app is up and copied to .env file.
This is my .env file
CURRENCY_SERVICE_HOST=https://URL.herokuapp.com
CURRENCY_SERVICE_PORT=53294 # I copied this port number from view logs section on heroku
Also I tried access without port but still can't connect. I can connect on localhost by he way. I just need to find correct connection credentials please help me

This is the first and the most basic test. Try accessing those URLs in the browser and see if the apps are running as expected and if they resolve.
If your API URI is
https://URL.herokuapp.com/api/v0/endpoint
Open the app API URI in a browser to ensure that it is working.
Next, presuming both services are back-end nodejs apps that need to talk to each other via server-to-server API calls, you want to ensure that communication between them is working on Heroku.
It seems like you're on the right track with troubleshooting and logging this step, but you definitely don't want to use the internal port number. You do want to use the public URL https://URL.herokuapp.com. When using HTTPS, it's always going to be on port 443.
Please take a look at this answer for additional help with configuring, deploying, and running microservices on Heroku. How to deploy microservices on Heroku
Hopefully, this helps. Good luck!

Related

Why is #nestjs/bull not able to connect to Heroku Redis?

This works for local redis-server
BullModule.forRoot({
redis: {
host: "localhost",
port: 6379,
db: 0,
password: ""
}
})
But if I use the DataStore Credentials on Heroku Redis, the bull board does not load and Heroku Logs gives an H12 error.
How can I get the BullModule to properly connect to Heroku Data for Redis?
Thanks!
You must specify the location of where redis is accessible. localhost:6379 is the default for running redis locally, but to deploy an application that uses Redis to Heroku, you will need to add the Connecting to Heroku Data for Redis add-on. Then, you'll need to pass the location of your Redis service via process.env.REDIS_URL to the BullModule.forRoot() constructor.
Be aware that encountering TLS issues in connecting to Redis like this are common. When I tried connecting using the format from PedroPovedaQ's answer, I ran into one.
There's a discusson on that here.
I suggest trying
BullModule.forRoot({
redis: "<redisurl given by heroku in env variable>"
})
This fixed the issue for me.

Shopify CLI - How to start a local server without ngrok?

My organization blocks ngrok, so every time I run the Shopify serve command, it fails with a connection error.
So is there any way to just start the Shopify local server? that way I can use cloudfared to tunnel the local server to a subdomain.
When I search on google I found no answer to this question.
I had success running the server without the ngrok.
Here are my steps:
Prepare a cloud server, install Nginx.
config domain settings, and forward the request to your local port.
If you are using a router, only router has a public IP, so you need to forward the request to your pc. You could config it in the router.
then you need to update .env file, update host value
Go partner.shopify.com, app settings. put your URL to the whitelist.
use npm run dev to start your project.
I also set HTTPS in nginx. Due to ngrok server is far away from my location. so after using this way. the starting time is much faster.
Start the server by
npm run dev
instead of,
shopify app serve

Problem deploying nginx on heroku in front of server on Go

I want to deploy to heroku nginx as a reverse proxy in front of my Go application.
I made a config file for nginx, but its samples presented here https://github.com/heroku/heroku-buildpack-nginx do not give an understanding of which port to specify in the proxy_pass directive to redirect to my application. These examples use unix socket listening instead of http.
upstream app_server {
server unix: /tmp/nginx.socket fail_timeout = 0;
}
But my application is running over http.
In addition, heroku uses random ports, which the application must retrieve from the PORT environment variable. However, now I have set this variable in the config for nginx. What port should my application run on now? If you specify your own port, this will not work, since heroku will say that the port is already busy.
I am completely discouraged by the difficulty of deploying a simple environment for my heroku application. None of the heroku instructions give a comprehensive understanding of how this can be done.
Please guide me on the right path.
P.S. For a couple of days of searching for an answer, I found only a lot of questions similar to mine and not a single answer.
Update.
I did as in this post Springboot application with nginx as proxy deploy on Heroku
But the author did not explain what she set in the APP_PORT variable. I set it to 3001 and got the same thing as here:
Nginx and Heroku. Serving Static Files

Does "heroku local" provide HTTPS proxying?

I've been playing around with a nodejs app on Heroku and got HTTPS setup pretty easily using Heroku's Automated Certificate Management, which manages the certificates and also adds headers to the incoming requests so I can see whether it came over HTTP or HTTPS.
I ran into some headaches developing locally as my local machine wasn't adding those headers and the logic to determine whether I was local was leaking throughout my app. I ended up using node's http-proxy lib to wrap my app when running locally, which worked pretty well even adding the X headers my app was using.
if (IN_DEVELOPMENT) {
const proxiedPort = 9090; // don't hit this directly
startServer(proxiedPort);
const httpProxy = require('http-proxy')
httpProxy.createServer({
target: {
host: 'localhost',
port: proxiedPort
},
ssl: {
key: fs.readFileSync('./dummy/key.pem', 'utf8'),
cert: fs.readFileSync('./dummy/cert.pem', 'utf8')
},
xfwd: true // add X-Forward-* headers as Heroku does
}).listen(EXTERNAL_PORT);
} else {
startServer(EXTERNAL_PORT);
}
After doing some more development I heard about the heroku local command that runs things locally and thought I was a complete idiot for wasting my time setting up the proxy, but after some testing it's just running my app using the Procfile and I still need to run this proxy locally.
Is there a workflow built-in to heroku CLI for handling the HTTPS proxy?

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