Unverified Commit e2ab63df authored by Aral Balkan's avatar Aral Balkan
Browse files

Add basic secure server

parent 8eddd82d
Pipeline #745 canceled with stages
# aspect-setup-1
# Hypha Aspect Setup Spike 1
\ No newline at end of file
## Blog post
## Usage
1. Create keys using [mkcert](https://github.com/FiloSottile/mkcert):
# If you haven’t used mkcert before, you must first create
# and install your local Certificate Authority (CA):
mkcert -install
# Generate your keys for localhost:
mkcert localhost
This will create the `localhost.pem` and `localhost-key.pem` files used by the Simple TLS spike.
(Note: for the certificate to be accepted without warning, you must restart your browser after running `mkcert -install`.)
2. Give Node.js permission to bind to ports < 1024 (i.e., 80 and 443) without being root:
sudo setcap 'cap_net_bind_service=+ep' $(which node)
3. Run the app:
node index.js
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hypha Aspect Setup Spike 1</title>
<h1>Hypha Aspect Setup Spike 1</h1>
\ No newline at end of file
const fs = require('fs')
const https = require('https')
const { pipeline } = require('stream')
const options = {
key: fs.readFileSync('localhost-key.pem'),
cert: fs.readFileSync('localhost.pem')
https.createServer(options, (request, response) => {
pipeline(fs.createReadStream('index.html'), response)
}).listen(443, () => {
console.log('Listening on port 443.')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment