Skip to content

Instantly share code, notes, and snippets.

@wesdeveloper
Created May 15, 2019 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesdeveloper/430383dd09c6f2f2763ff5621641f1c7 to your computer and use it in GitHub Desktop.
Save wesdeveloper/430383dd09c6f2f2763ff5621641f1c7 to your computer and use it in GitHub Desktop.
Https server with express.
const fs = require("fs");
const https = require("https");
const express = require("express");
// Instância express
const app = express();
app.get("/", (req, res) => {
res.send("Hello world using HTTPS!");
});
// Carrega o certificado e a key necessários para a configuração.
const options = {
key: fs.readFileSync("server.key"),
cert: fs.readFileSync("server.cert")
};
// Cria a instância do server e escuta na porta 3000
https.createServer(options, app).listen(3000);
// Você pode testar com o curl: curl -k https://localhost:3000
// Retorno --> Hello world using HTTPS!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment