Add basic secure server

parent 8eddd82d
Pipeline #745 canceled with stages
node_modules
localhost*.pem
# aspect-setup-1
# Hypha Aspect Setup Spike 1
https://ar.al/2019/01/10/hypha-spike-aspect-setup-1/
\ No newline at end of file
## Blog post
https://ar.al/2019/01/10/hypha-spike-aspect-setup-1/
## Usage
1. Create keys using [mkcert](https://github.com/FiloSottile/mkcert):
```bash
# 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:
```bash
sudo setcap 'cap_net_bind_service=+ep' $(which node)
```
3. Run the app:
```bash
node index.js
```
<!DOCTYPE html>
<html lang="en">
<head>
<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>
</head>
<body>
<h1>Hypha Aspect Setup Spike 1</h1>
</body>
</html>
\ 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