secure: true
option for both setting cookies and tokens to use HTTPS! HTTPS refers to the HTTP protocol plus data encryption using SSL/TLS. Netscape originally invented the now deprecated SSL (Secure Socket Layer) protocol in the mid 90's for secured encryption on the web. Netscape handed over the control of the protocol to the Internet Engineering Task Force (IETF), which then released TLS (Transport Layer Security), which is basically just an upgraded version of SSL maintained by the IETF.
When a web server is configured to use SSL/TLS encryption, it encrypts messages to the client using the public key of the client. The process of encrypting messages to the client involves several steps:
Symmetric keys perform more than 200 times faster than asymmetric keys but they are not as secure. Which is why asymmetric keys are used to securely transport the generated symmetric keys from the client to server. This establishes a secure connection between the server and client, since now both sides and encrypt and decrypt messages using the same symmetric key.
brew install mkcert
mkcert -install
mkcert -key-file key.pem -cert-file cert.pem example.com *.example.com
mkcert -key-file key.pem -cert-file cert.pem localhost 127.0.0.1 ::1
const https = require('https');
const fs = require('fs');
https
.createServer(
{
key: fs.readFileSync(__dirname + '/key.pem', 'utf-8'),
cert: fs.readFileSync(__dirname + '/cert.pem', 'utf-8'),
},
function (req, res) {
res.write('Congrats! You made https server now :)');
res.end();
}
)
.listen(3001);
const https = require('https');
const fs = require('fs');
const express = require('express');
const app = express();
https
.createServer(
{
key: fs.readFileSync(__dirname + '/key.pem', 'utf-8'),
cert: fs.readFileSync(__dirname + '/cert.pem', 'utf-8'),
},
app.use('/', (req, res) => {
res.send('Congrats! You made https server now :)');
})
)
.listen(3001);
The differences between HTTPS, SSL, and TLS: A visual guide
(Advanced) ngrok: Easily share your local server (Local Tunneling)