Created
May 30, 2017 01:28
-
-
Save jazzyjackson/e1f3ad8944ee26fefa5267af729f9c06 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
const fs = require('fs') | |
const exec = require('child_process').exec | |
const http = require('http') | |
http.createServer((request,response) => ({ | |
'GET': () => fs.createReadStream('.' + request.url, 'utf8') | |
.on('error', err => response.end(JSON.stringify(err))) | |
.pipe(response), | |
'POST': () => exec(decodeURI(request.url.split('?')[1])).stdio.forEach(stdio => stdio.pipe(response)), | |
'PUT': () => request.pipe(fs.createWriteStream('.' + request.url, 'utf8')) | |
.on('finish', () => response.end()), | |
'DELETE': () => fs.unlink('.' + request.url, err => response.end( err ? JSON.stringify(err) : 'OK')) | |
})[request.method]()).listen(3000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment