project.js: handle case no category is provided
[beagleboard.org.git] / node / serve
blob6bd1a68afc4d5d5cc17bd94b024c6ddad5ddad62
1 #!/usr/bin/env node
2 var express = require('express');
3 var formidable = require('formidable');
4 var util = require('util');
5 var fs = require('fs');
7 var uploadDir = __dirname + '../static/uploads';
8 var documentRoot = __dirname + '../static';
10 var app = express();
11 app.post('/upload', function (req, res) {
12     var form = new formidable.IncomingForm();
13     form.uploadDir = uploadDir;
14     form.keepExtensions = true;
15     form.parse(req, function(err, fields, files) {
16         res.writeHead(200, {'content-type': 'text/plain'});
17         res.write('received upload:\n\n');
18         res.end(util.inspect({fields: fields, files: files}));
19         fs.rename(files.upload.path,
20             uploadDir + '/' + files.upload.name, function(err) {});
21     });
22 });
23 app.use(express.static(documentRoot));
24 app.use(express.directory(documentRoot));
25 app.use(express.methodOverride());
26 app.use(app.router);
27 app.listen(8081);