Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

port example from 1.x

  • Loading branch information...
commit 57b830d0e3c218cdfe1899597ac1940731a228a1 1 parent 42a9f9a
@tj tj authored
Showing with 29 additions and 0 deletions.
  1. +29 −0 examples/bodyParser.js
View
29 examples/bodyParser.js
@@ -0,0 +1,29 @@
+
+var connect = require('../')
+ , http = require('http');
+
+// visit form.html
+
+var app = connect()
+ .use(connect.static(__dirname + '/public'))
+ .use(connect.bodyParser())
+ .use(function(req, res, next){
+ console.log(req.method);
+ if ('GET' != req.method) return next();
+ res.statusCode = 302;
+ res.setHeader('Location', 'form.html');
+ res.end();
+ })
+ .use(function(req, res){
+ res.setHeader('Content-Type', 'text/html');
+ res.write('<p>thanks ' + req.body.name + '</p>');
+ res.write('<ul>');
+ req.body.images.forEach(function(image){
+ var kb = image.size / 1024 | 0;
+ res.write('<li>uploaded ' + image.name + ' ' + kb + 'kb</li>');
+ });
+ res.end('</ul>');
+ });
+
+http.Server(app).listen(3000);
+console.log('Server started on port 3000');
Please sign in to comment.
Something went wrong with that request. Please try again.