Created
November 12, 2020 06:35
-
-
Save mayankchoubey/60288a3c3b86a55d0365df239cfee6bc to your computer and use it in GitHub Desktop.
This file contains 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 { 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 })}); | |
} |
This file contains 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
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