SIGN IN SIGN UP
vercel / micro UNCLAIMED

Asynchronous HTTP microservices

0 0 53 TypeScript
2018-04-23 17:33:13 -07:00
const https = require('https');
const {run, send} = require('micro');
2017-07-19 14:54:26 +03:00
const {key, cert, passphrase} = require('openssl-self-signed-certificate');
2017-07-19 14:54:26 +03:00
2018-04-23 17:33:13 -07:00
const PORT = process.env.PORT || 3443;
2017-07-19 14:54:26 +03:00
const options = {key, cert, passphrase};
2017-07-19 14:54:26 +03:00
2018-04-23 17:33:13 -07:00
const microHttps = fn => https.createServer(options, (req, res) => run(req, res, fn));
2017-07-19 14:54:26 +03:00
const server = microHttps(async (req, res) => {
2018-04-23 17:33:13 -07:00
send(res, 200, {encrypted: req.client.encrypted});
});
2017-07-19 14:54:26 +03:00
2018-04-23 17:33:13 -07:00
server.listen(PORT);
console.log(`Listening on https://localhost:${PORT}`);