简体   繁体   中英

node.js localhost https server not working anything

const https = require('https');
const fs = require('fs');

const options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};

https.createServer(options,(req,res)=>{

  console.log('https server start');
}).listen(8080,'localhost');

Dear every one, I tried make https server... and this code. But not working.

Before i make key.pem, cert.pem for localhost server

Like this code

openssl genrsa 1024 > key.pem
openssl req -x509 -new -key key.pem > cert.pem

and this thing in the same folder

but not working like this enter image description here

Thank you and Regards.!

Your "it's not working" image isn't showing any errors, so it seems to start up just fine.

However, the code that handles the request isn't actually sending back a response, which would result in requests just "hanging".

Instead, try this:

https.createServer(options, (req, res) => {
  res.end('Hello, world!');
}).listen(8080, 'localhost', () => {
  console.log('https server start');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM