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?
Related
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!
Ubuntu 20.04
Apache2
I have been developing a Microsoft Teams Tab and I am running it on my own cloud-based server. I have tested using ngrok and it is working great. Now I need to move away from using ngrok and tunnel my node.js myself without using ngrok
Problem is that I am new to node.js and so some of this I am just learning. From my understanding, I need to use gulp/browsersync but I am not sure if I am heading in the right direction. I have tried many different configs in my gulpfile.js file but nothing seems to work.
gulp.task('browser-sync', function () {
browserSync.init(null, {
proxy: 'teams.example.com',
open: false
});
});
Can someone point me in the right direction on how I can create a secure tunnel?
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
I'm trying to set up a chat application on heroku with redis and socket.io, but I can't figure out what uri am I suppose to put on the client side.
All uri's I have tried, give me a 404, name_not_resolved, or timeout erorrs.
I have one heroku app, which is running a node.js buildpack, and all it does is runs the socket.js file.
And I have another php heroku app which has the laravel back end with redis broadcasting and a vue front end.
The broadcasting is set up so that when someone publishes a post or makes a GET request of '/', an event is fired on 'new-post-channell' and 'user-entered-chat-channel' respectively.
I can go into the bash of the socket.js app and run 'node socket.js'. I can see that it connects to heroku's redis addon Amazon server and picks up on the broadcasts.
I can also go into the heroku's redis-cli of the second app, into the monitor mode, and see that broadcasts are being picked up as intended.
It all worked in a vagrant homestead virtual server, but doesn't on heroku.
var socket = io('redis://h:oaisuhaosiufhasodiufh#ec2-99-81-167-43.eu-west-1.compute.amazonaws.com:6639');
(and maybe you also know how can I run the 'node socket.js' command on my first app automatically, so that I wouldn't have to go into the heroku's bash and run it manually?)
All and all.. I finally got a VPS on Vultr.com.. And ran into the same problem..
So the answer is
if you have https done.. then you need to put the domain you are on.
io('https://'+ window.location.hostname, {reconnect: true});
You need to navigate to your nginx configuration files and edit them.. I've set up mine in the sites-available section.
/etc/nginx/sites-available/yourDomainOrIp.conf
3.
You will have these sections "location" in the configuration file. Make a new one. I put mine before the others.
location /socket.io/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass "http://localhost:3000/socket.io/";
}
this section means if you visit something /socket.io/ it will be redirected to localhost port 3000.
And on local host port 3000 I have the nodejs app listening
var server = require('http').Server();
var io = require('socket.io')(server);
var Redis = require('ioredis');
var redisNewMessage = new Redis();
var redisUserEntered = new Redis();
server.listen(3000);
Soo.. I still don't know how to fully answer the question.. but basically:
in that io() you would need to pass an address which eventually passes the "/socket.io/polling%something&something" to the localhost and the port of the server in which nodejs app is sitting in.
That amazon link stays in the nodejs new Redis ().. Socket.io has to connect to the nodejs app file and then it all should work.
I have created an application and want to serve it using caddy.
On my localhost if I run the application on 127.0.0.1:9000 and set it as proxy in
the caddyfile it works. I figured I have to serve my website similarly on my production as well.
Now I am trying to serve it on my ec2 instance. I tried serving it on localhost, 127.0.0.1 and even the domain directly itself but caddy does not work here. Oneof the things I noticed is that the url is automatically changing from http tp https, I figure it means that at least caddy is running and recognizing the request but is not actually able to find the content.
Below is my CaddyFile.
abc.xyz.com {
proxy / zbc.xyz.com:9000 {
transparent
}
}