public
Last active — forked from substack/bbs.js

Running a node.js REPL over `curl`

  • Download Gist
bbs.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/**
* Requires node v0.7.7 or greater.
*
* To connect: $ curl -sSNT. localhost:8000
*/
 
var http = require('http')
, repl = require('repl')
, buf0 = new Buffer([0])
 
var server = http.createServer(function (req, res) {
res.setHeader('content-type', 'multipart/octet-stream')
 
res.write('Welcome to the Fun House\r\n')
repl.start({
prompt: 'curl repl> '
, input: req
, output: res
, terminal: false
, useColors: true
, useGlobal: false
})
 
// log
console.log(req.headers['user-agent'])
 
// hack to thread stdin and stdout
// simultaneously in curl's single thread
var iv = setInterval(function () {
res.write(buf0)
}, 100)
 
res.connection.on('end', function () {
clearInterval(iv)
})
})
server.listen(8000)
output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
☮ ~ (master) ⚡ curl -sSNT. localhost:8000
Welcome to the Fun House
curl repl> process.platform
'darwin'
curl repl> process.arch
'x64'
curl repl> process.cwd()
'/Users/nrajlich'
curl repl> path
{ resolve: [Function],
normalize: [Function],
join: [Function],
relative: [Function],
dirname: [Function],
basename: [Function],
extname: [Function],
_makeLong: [Function] }
curl repl> ^C
☮ ~ (master) ⚡

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.