Skip to content

Instantly share code, notes, and snippets.

@dcmwong
Created May 21, 2021 08:58
Show Gist options
  • Save dcmwong/c9bda3336136b42023ce9d9792983978 to your computer and use it in GitHub Desktop.
Save dcmwong/c9bda3336136b42023ce9d9792983978 to your computer and use it in GitHub Desktop.
Simple TLS server
import * as http from 'http'
import * as fs from 'fs'
import * as net from 'net'
import * as tls from 'tls'
const options = {
cert: fs.readFileSync('server.crt'),
key: fs.readFileSync('server.key'),
// ca: [fs.readFileSync('public2crt'), fs.readFileSync('public.crt')],
ca: fs.readFileSync('public.crt'),
}
const start = () => {
const server = tls.createServer(options, connection => {
let buffer = ''
connection.on('data', data => {
console.log('received:', data)
buffer.push('respond with something')
connection.write('respond with something')
connection.end()
return
}
})
})
server.listen(1234, () => console.log('opened TCP server on', server.address()))
}
start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment