How to bind express http and https server to same port - node.js

I want to run my express server on the same port using http & https
for e.g.
http http://example.com:3000
https https://example.com:3000

You can use httpolyglot.
https://github.com/mscdex/httpolyglot
It is a module for serving http and https connections over the same port.

Related

Application working on http but not on https

Background: I have two backend instances running haproxy, apache, nodejs on ports 4000 and 8007 for haproxy, 80 for httpd, 3000 3007 3012 running node. I have a staging site which is running on this instance. I have signed certificate installed at ELB level and ELB listening on https 443 port to backend http 80 port.
Issue: When I tried to login to the stating url with http then the backend is working fine on port 80 and 3000, network flow logs also returning status code as Ok for request to http://stating _url:3000. But when I tried to access site on https then I am getting status as "blocked:mixed-content" for https://stating _url:3000 request. Please refer to below screenshots
Below is output for http which is working as expected
Below is the output for https which is not working as expected
I tried different protocols for listeners at ELB level. I dont understand why ELB on port 80 sends request to port 80 on backend server and all works fine but same ELB on port 443 sends request to same port 80 on backend server but fails to establish connection with 3000.

Why are HTTP curl/Postman requests to a HTTPS server working? (Node, AWS)

I've set up a HTTPS Node server on AWS EC2 which runs on port 4443 and set up Nginx to redirect requests(port 443).
https.createServer(options, app).listen(4443, function(){
console.log("https server started at port 4443");
});
The HTTPS server is working fine, I get a secure connection on browsers and
curl https://mydomain/apiroute works
Now, when I do
curl http://mydomain/apiroute the requests still work. The same goes for Postman.
I know that I can redirect all HTTP traffic to HTTPS using something like 301 redirects but my question is, why does the server respond to HTTP API calls inspite of there being no "HTTP" server?
Additionally, I use a letsencrypt generated certificate.

How do I use HTTPS port on clould9 ide?

I am just running some tests on c9.io - but I am stuck on how to get the HTTPS server to run.
I am using the port given in process.env.PORT which links up to the browser in c9, but there doesn't seem to an HTTPS port. In a local environment I use port 3001 for HTTPS.
The Cloud9 workspaces don't support custom SSL certificates yet so you won't be able to start an HTTPS server from there, but your http server running on 0.0.0.0:8080 will be accessible via both HTTP and HTTPS.

Redirect http request(via browser) to local server

I have nodejs http server running on port 9000.
Now for some hostname how do i redirect normal request to this port.
Example : if I hit www.specficDomain.com in browser, it should go to www.specficDomain.com:9000.
Thanks,
Shantanu

Running a forward proxy server in nodejitsu using node js

I am new to proxy server. What I want to do is: I want to write some node.js code, and then upload to my nodejitsu account to run as a proxy server. Then I would like to use my nodejitsu proxy server on my computer, by configuring the http proxy as "abc.jit.su" (my jitsu URL), and the port as "80" in Chrome, Firefox or IE. That's to say, I want my nodejitsu proxy server to have the same function as the proxies listed here: http://www.freeproxylists.net/. Any ideas?
You can write a simple proxy using the request module, like this:
var http = require('http'),
request = require('request');
// For nodejitsu, this will be port 80 externally
var port = process.env.PORT || 8000;
http.createServer(function(req,res) {
req.pipe(request(req.url)).pipe(res)
}).listen(port);
However, this will only work with http, not https.
Nodejitsu also produces a proxy module, you may get some ideas on what to do next by looking at that.

Resources