Skip to content

Instantly share code, notes, and snippets.

@mayankchoubey
Created November 12, 2020 06:35
Show Gist options
  • Save mayankchoubey/60288a3c3b86a55d0365df239cfee6bc to your computer and use it in GitHub Desktop.
Save mayankchoubey/60288a3c3b86a55d0365df239cfee6bc to your computer and use it in GitHub Desktop.
import { serveTLS } from "https://deno.land/std/http/server.ts";
const certFile: string= Deno.env.toObject()["CERT_FILE"];
const keyFile: string= Deno.env.toObject()["KEY_FILE"];
const options = {
hostname: "localhost",
port: 3000,
certFile,
keyFile
};
const decoder = new TextDecoder();
for await (const req of serveTLS(options)) {
const body=JSON.parse(decoder.decode(await Deno.readAll(req.body)));
req.respond({body: JSON.stringify({ name: body.name })});
}
const https = require('https');
const fs = require('fs');
const options = {
key: fs.readFileSync(process.env.KEY_FILE, 'utf8'),
cert: fs.readFileSync(process.env.CERT_FILE, 'utf8')
};
var server = https.createServer(options, (request, response) => {
let data = '';
request.on('data', chunk => data += chunk);
request.on('end', () => {
response.writeHead(200, {"Content-Type": "application/json"});
response.end(JSON.stringify({name: JSON.parse(data).name}));
});
});
server.listen(process.env.PORT||3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment