diff options
author | Gianni Ceccarelli <gianni.ceccarelli@broadbean.com> | 2018-02-21 13:46:43 +0000 |
---|---|---|
committer | Gianni Ceccarelli <gianni.ceccarelli@broadbean.com> | 2018-02-21 13:46:43 +0000 |
commit | 0bf2119539439c443c1e34ce3065ffe8cb237d6f (patch) | |
tree | b5a9b41d28e577a3d3dff2fdea58bff934bdd1e4 | |
parent | fix deps (diff) | |
download | color-0bf2119539439c443c1e34ce3065ffe8cb237d6f.tar.gz color-0bf2119539439c443c1e34ce3065ffe8cb237d6f.tar.bz2 color-0bf2119539439c443c1e34ce3065ffe8cb237d6f.zip |
simple HTTP echo server
-rw-r--r-- | index.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/index.js b/index.js new file mode 100644 index 0000000..ba60515 --- /dev/null +++ b/index.js @@ -0,0 +1,20 @@ +const http = require('http'); + +const server = http.createServer((req, res) => { + let filename = req.headers['filename']; + let buffer = ''; + res.setHeader('Content-type','text/plain'); + res.statusCode = 200; + req.on('end', () => { + res.write(buffer, '', () => { res.end() }); + }); + req.on('data', (chunk) => { + buffer += chunk; + }); +}); + +server.on('clientError', (err, socket) => { + socket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); +}); + +server.listen(8000); |