Browse files

Add uploader middleware

  • Loading branch information...
1 parent 9e3ff82 commit f6d91e2d4dce666845ae55bedab4698380a1b0c8 @creationix committed Jul 30, 2011
Showing with 17 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +16 −0 uploader.js
View
1 .gitignore
@@ -0,0 +1 @@
+node_modules
View
16 uploader.js
@@ -0,0 +1,16 @@
+var FS = require('fs'),
+ Url = require('url');
+
+module.exports = function setup(mount, root) {
+ return function handle(req, res, next) {
+ if (req.method !== "PUT") return next();
+ if (!req.uri) { req.uri = Url.parse(req.url); }
+ var stream = FS.createWriteStream(req.uri.pathname);
+ stream.on('error', next);
+ req.pipe(stream);
+ req.on('end', function () {
+ res.writeHead(200, {});
+ res.end();
+ });
+ };
+};

0 comments on commit f6d91e2

Please sign in to comment.