Skip to content

Instantly share code, notes, and snippets.

@adohe-zz
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save adohe-zz/c6659c7a0639fd68f3cc to your computer and use it in GitHub Desktop.

Select an option

Save adohe-zz/c6659c7a0639fd68f3cc to your computer and use it in GitHub Desktop.
use connect to parse upload...
var http = require('http'),
connect = require('connect'),
fs = require('fs'),
util = require('util'),
port = process.env.PORT || 8000,
form = fs.readFileSync('./form.html');
var app = connect();
app.use(function (req, res, next) {
if (req.method === 'GET') {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(form);
return;
}
next();
});
var getRawBody = require('raw-body');
app.use(function (req, res, next) {
getRawBody(req, {
length: req.headers['content-length'],
limit: '1mb',
encoding: 'utf8'
}, function (err, string) {
if (err)
return next(err);
req.text = string;
next();
});
});
app.use(function (req, res) {
// you can output here
console.log(req.text);
res.end('beep boop\n');
});
http.createServer(app).listen(port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment