Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / test / data / third_party / spaceport / server / index.js
blobee5cd365d0b94fe8f3138b775d9552c874bde1f5
1 var express = require('express');
2 var app = express.createServer();
4 app.configure(function () {
5 app.use(express.static(__dirname + '/../'));
6 app.use(express.logger());
7 app.use(app.router);
8 });
10 app.configure('development', function(){
11 app.use(express.errorHandler({
12 dumpExceptions: true,
13 showStack: true
14 }));
15 });
17 app.configure('production', function(){
18 app.use(express.errorHandler());
19 });
21 var UPLOAD_DIRECTORY = __dirname + '/uploads';
23 function saveUpload(data) {
24 var filename = UPLOAD_DIRECTORY + '/' + (data.date + '_' + data.ip).replace(/[^A-Za-z0-9_.-]/g, '_') + '.json';
25 require('fs').writeFile(filename, JSON.stringify(data) + '\n', 'utf8');
28 app.post('/results', function (req, res) {
29 var date = Date.now();
31 var jsonData = '';
32 req.on('data', function (data) {
33 jsonData += data.toString('utf8');
34 });
36 req.on('end', function () {
37 var userData = JSON.parse(jsonData);
38 saveUpload({
39 date: date,
40 ip: req.connection.remoteAddress,
41 userData: userData
42 });
43 res.end();
44 });
46 req.resume();
47 });
49 app.listen(3002);
50 console.log('Listening on :3002');