-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
76 lines (60 loc) · 1.89 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var express = require('express');
var url = require('url');
var app = express();
var dburl = 'genredraw';
var collections = ['frames', 'pallets'];
var mongojs = require('mongojs');
var db = mongojs(dburl, collections);
var bodyParser = require('body-parser')
app.use( bodyParser.json({limit: '50mb'}) ); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true,
limit: '50mb'
}));
app.get('/insert/frame', function (req, res) {
var url_parts = url.parse(req.url, true);
var query = url_parts.query;
var result = query['status'];
db.frames.insert(JSON.parse(result));
res.send(result);
});
app.post('/insert/pallet', function (req, res) {
var raw = req.body.pallet;
var parsed = JSON.parse(raw);
console.log(raw);
console.log(parsed);
var result = {
pallet: parsed,
filename: req.body.filename
};
db.pallets.insert(result);
res.send(result);
});
app.get('/get/pallet', function (req, res) {
res.send(db.pallets.find({filename: req.params.pallet}));
});
//.skip(parseInt(query['index'], 10)).limit(1)
app.get('/get/frame', function (req, res) {
var url_parts = url.parse(req.url, true);
var query = url_parts.query;
var result = query['status'];
console.log(query['filename']);
db.frames.find({filename: query['filename']}).sort({totalDraws:1}).skip(parseInt(query['index'], 10)).limit(1,
function(err, result) {
console.log(query['filename']);
console.log(query['index']);
console.log(result);
res.send(result);
});
});
app.get('/', function (req, res) {
res.sendfile('index.html');
});
app.get('*', function (req, res) {
res.sendfile('.' + req.path);
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Listening at http://%s:%s', host, port);
});