Browse Source

Added HTTPS example (#264)

master
Albin Ekblom 7 years ago
committed by Leo Lamprecht
parent
commit
098c210d6e
  1. 21
      examples/with-https/index.js
  2. 13
      examples/with-https/package.json

21
examples/with-https/index.js

@ -0,0 +1,21 @@
const https = require('https')
const { run, send } = require('micro')
const cert = require('openssl-self-signed-certificate')
const PORT = process.env.PORT || 3443
const options = {
key: cert.key,
cert: cert.cert,
passphrase: cert.passphrase
}
const microHttps = fn => https.createServer(options, (req, res) => run(req, res, fn))
const server = microHttps(async (req, res) => {
send(res, 200, { encrypted: req.client.encrypted })
})
server.listen(PORT)
console.log(`Listening on https://localhost:${PORT}`)

13
examples/with-https/package.json

@ -0,0 +1,13 @@
{
"name": "with-https",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "node ."
},
"dependencies": {
"micro": "latest",
"openssl-self-signed-certificate": "^1.1.6"
}
}
Loading…
Cancel
Save