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());
10 app
.configure('development', function(){
11 app
.use(express
.errorHandler({
17 app
.configure('production', function(){
18 app
.use(express
.errorHandler());
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();
32 req
.on('data', function (data
) {
33 jsonData
+= data
.toString('utf8');
36 req
.on('end', function () {
37 var userData
= JSON
.parse(jsonData
);
40 ip
: req
.connection
.remoteAddress
,
50 console
.log('Listening on :3002');