0

What I am trying to do is to redirect an http request to https on nodejs express...

The thing is i have my https service listening on port 444, and i want to redirect an http req on the port 444 to https.

for example when i request this "https://url:444" works

when i do this "url:444" the broser put the "https://"

but when i do this "http://url:444" there is a timeout.

I been trying some http redirect to https things, but almost every clue i found it's two services one listening on port 80 (http) and the 443 (https) but that does not work in my case.

I run my server like this.

var app = require('express')()
, https = require('https')


  PORT = process.env.PORT || 443;

  var privateKey = fs.readFileSync('../keys/server.key', 'utf8')
  , certificate = fs.readFileSync('../keys/server.crt', 'utf8')
  , credentials = { key : privateKey, cert : certificate }
  , httpsServer = https.createServer(credentials, app);

  httpsServer.listen(PORT, function(){
    'use strict';
    console.log('Listen on port ' + PORT);
  });
Juan Miguel
  • 71
  • 1
  • 4
  • Do you have some code? – crackmigg Feb 04 '16 at 18:08
  • @migg that code help? – Juan Miguel Feb 04 '16 at 18:18
  • Yes if that is your only code, then you are simply not having an HTTP server listening, so that gives a timeout. – crackmigg Feb 04 '16 at 18:20
  • Well there are a lot of code more, but just middlewares with api routes and etc. So There is a timeout because the server is listening on port 444, but i can't see the request on the https service? – Juan Miguel Feb 04 '16 at 18:27
  • 1
    [answered here](http://stackoverflow.com/questions/22453782/nodejs-http-and-https-over-same-port) – josh3736 Feb 04 '16 at 18:28
  • @josh3736 dude, that question is so different to mine, he ask how to listen on the same port, i asked if i can listen an http request on an https service, i saw that question earlier and doesn't work for my case. – Juan Miguel Feb 04 '16 at 18:34
  • The short answer is no you cannot. All the other answers allude to this but basically one protocol per port is how it works. – bknights Feb 04 '16 at 18:35
  • That's exactly what you're asking -- if you want to respond to HTTP requests from a HTTPS service running on a particular port, you need to listen for HTTP and HTTPS on the same port. – josh3736 Feb 04 '16 at 18:39
  • @bknights tanks, thats what i needed to know. – Juan Miguel Feb 04 '16 at 18:42

0 Answers0