-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,069 additions
and
292 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const http = require('http'); | ||
|
||
const PORT = 80; | ||
const HOST = '0.0.0.0'; | ||
|
||
const requestHandler = async (request, response) => { | ||
const body = await getBody(request); | ||
|
||
const responseText = 'Hello: ' + body; | ||
|
||
response.statusCode = 200; | ||
response.setHeader('Content-Type', 'text/plain'); | ||
response.setHeader('Content-Length', responseText.length); | ||
response.end(responseText); | ||
}; | ||
|
||
// Create HTTPS server with the provided SSL credentials and request handler | ||
const server = http.createServer(requestHandler); | ||
|
||
server.listen(PORT, HOST, () => { | ||
console.log(`Server listening on https://${HOST}:${PORT}`); | ||
}); | ||
|
||
function getBody(request) { | ||
return new Promise((resolve) => { | ||
const bodyParts = []; | ||
let body; | ||
request.on('data', (chunk) => { | ||
bodyParts.push(chunk); | ||
}).on('end', () => { | ||
body = Buffer.concat(bodyParts).toString(); | ||
resolve(body) | ||
}); | ||
}); | ||
} |
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
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
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
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
Oops, something went wrong.