Created
May 21, 2021 08:58
-
-
Save dcmwong/c9bda3336136b42023ce9d9792983978 to your computer and use it in GitHub Desktop.
Simple TLS server
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
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