Last active
August 29, 2015 14:04
-
-
Save adohe-zz/c6659c7a0639fd68f3cc to your computer and use it in GitHub Desktop.
use connect to parse upload...
This file contains hidden or 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
| 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