-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (61 loc) · 1.63 KB
/
index.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
77
78
79
80
81
82
var express = require('express');
var http = require('http');
var path = require('path');
//var handlebars = require('express3-handlebars')
var bodyParser = require('body-parser')
var total_gallery = 0;
var gallery_map = [];
var title = "untitle";
var date = (new Date()).toString().split(' ').splice(1,3).join(' ');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
app.get('/', function (req, res) {
res.redirect('login.html');
})
//GLOBAL VARIABLE
var total = 100;
//localhost:3000/store
app.get('/store', function(req, res) {
if(req.query.inc !== null) {
total+=parseInt(req.query.inc);
}
//JSON VARIABLE
var data = {
total: total,
name: "christian"
};
//SENDS JSON
res.send(data);
});
app.get('/getMoney', function(req, res) {
var data = {
total: total,
name: "christian"
}
res.send(data);
});
app.post('/gallery', function (req, res) {
res.send([total_gallery]);
total_gallery += parseInt(req.body.val);
if (req.body.title != undefined && req.body.title != ""){
title = req.body.title;
}
})
app.post('/map', function (req, res) {
gallery_map = req.body.map;
})
app.get('/map', function (req, res) {
res.send(gallery_map);
})
app.get('/info', function(req, res) {
res.send({'title': title, "date" : date});
})
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});