Created
May 15, 2019 22:59
-
-
Save wesdeveloper/430383dd09c6f2f2763ff5621641f1c7 to your computer and use it in GitHub Desktop.
Https server with express.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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