diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2022-07-10 17:20:37 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2022-07-10 17:20:37 -0400 |
| commit | 6b8154ba82c8089bcb47e2d3b6fea66353ba27bc (patch) | |
| tree | 6c1ef956a2e46b1fc7fdabe56dd60da67f243398 /WebStream.js | |
| parent | 10e93faf891c3fa3a68edb59d4ffb9d939680dc6 (diff) | |
| download | DLAP-6b8154ba82c8089bcb47e2d3b6fea66353ba27bc.tar.gz DLAP-6b8154ba82c8089bcb47e2d3b6fea66353ba27bc.tar.bz2 DLAP-6b8154ba82c8089bcb47e2d3b6fea66353ba27bc.zip | |
Fixed an issue where it doesn't shuffle properly
Diffstat (limited to 'WebStream.js')
| -rw-r--r-- | WebStream.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/WebStream.js b/WebStream.js new file mode 100644 index 0000000..efe36c8 --- /dev/null +++ b/WebStream.js @@ -0,0 +1,33 @@ +import { createServer } from 'node:http'; +const port = 1337; + +export function webServer() { + const server = createServer((req, res) => { + let body = '{"test": "test"}'; + // Get the data as utf8 strings. + // If an encoding is not set, Buffer objects will be received. + req.setEncoding('utf8'); + + // Readable streams emit 'data' events once a listener is added. + req.on('data', (chunk) => { + body += chunk; + }); + + // The 'end' event indicates that the entire body has been received. + req.on('end', () => { + try { + const data = JSON.parse(body); + // Write back something interesting to the user: + res.write(typeof data); + res.end(); + } catch (er) { + // uh oh! bad json! + res.statusCode = 400; + return res.end(`error: ${er.message}`); + } + }); + }); + + server.listen(port); + console.log(`Web server started! Port: ${port}`); +} |
