W
W
webe2018-02-10 12:41:16
Node.js
webe, 2018-02-10 12:41:16

How to make HTTPS?

Can anyone describe an approximate algorithm for how to implement HTTPS?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Balintodd, 2018-02-10
@webe

https://nodejs.org/api/https.html

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

const options = {
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};

https.createServer(options, (req, res) => {
  res.writeHead(200);
  res.end('hello world\n');
}).listen(8000);

Here is an easy way to do it. For almost all popular frameworks, there is also documentation with examples.
In the case of nodejs, I received pem keys by manually installing https://letsencrypt.org/ on the server .

S
Sergey Gornostaev, 2018-02-10
@sergey-gornostaev

Opens the documentation , and there ... Oh gods, there is not an exemplary algorithm, there is a specific example!

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

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

https.createServer(options, (req, res) => {
  res.writeHead(200);
  res.end('hello world\n');
}).listen(443);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question