4

I'm trying to add ssl certificates to my node server but my webpage continues to load in http and not https. I was wondering if someone can point me in the right direction. Kind of pulling my hair out lol. Here is a snippet of the some of the important code:

var options = { key: fs.readFileSync('/home/ec2-user/key.pem'), cert: fs.readFileSync('/home/ec2-user/cert.pem'), ca: fs.readFileSync('/home/ec2-user/ca.pem'), }; var app = express(); app.set('root', __dirname); https.createServer(options, app); app.listen(APP_PORT, APP_HOST); // Listener endpoint; handled in middleware app.get('/listen', function(){}); 

1 Answer 1

4

You are setting your Express application to listen instead of your HTTPS server. Use this instead:

var https = require('https'); var express = require('express'); var app = express(); var options = { key: fs.readFileSync('/home/ec2-user/key.pem'), cert: fs.readFileSync('/home/ec2-user/cert.pem'), ca: fs.readFileSync('/home/ec2-user/ca.pem') }; app.set('root', __dirname); app.get('/listen', function(req, res) { // respond here }); var server = https.createServer(options, app); server.listen(APP_PORT, APP_HOST); 

You don't need to specify an IP for the application if you don't have multiple addresses on your machine.

Sign up to request clarification or add additional context in comments.

2 Comments

Hm thanks for the response. When I make those changes, the page doesn't load and just hangs.
Nevermind got it working!! I did server.listen(8000); and didn't include the host. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.