Created
April 22, 2018 10:20
-
-
Save DavidMellul/e85e1c94a708a4fdf53a0cb77f630cb0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Dependencies | |
const fs = require('fs'); | |
const http = require('http'); | |
const https = require('https'); | |
const express = require('express'); | |
const app = express(); | |
// Certificate | |
const privateKey = fs.readFileSync('/etc/letsencrypt/live/yourdomain.com/privkey.pem', 'utf8'); | |
const certificate = fs.readFileSync('/etc/letsencrypt/live/yourdomain.com/cert.pem', 'utf8'); | |
const ca = fs.readFileSync('/etc/letsencrypt/live/yourdomain.com/chain.pem', 'utf8'); | |
const credentials = { | |
key: privateKey, | |
cert: certificate, | |
ca: ca | |
}; | |
app.use((req, res) => { | |
res.send('Hello there !'); | |
}); | |
// Starting both http & https servers | |
const httpServer = http.createServer(app); | |
const httpsServer = https.createServer(credentials, app); | |
httpServer.listen(80, () => { | |
console.log('HTTP Server running on port 80'); | |
}); | |
httpsServer.listen(443, () => { | |
console.log('HTTPS Server running on port 443'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment