-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
90 lines (68 loc) · 2.31 KB
/
server.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
83
84
85
86
87
88
89
90
/*jslint node: true, nomen: true, unparam: true, es5: true */
'use strict';
var express = require('express'),
url = require('url'),
_ = require('underscore'),
JsonProvider = require('./json-provider').JsonProvider,
// ApiDataProvider = require('./api-data-provider').ApiDataProvider,
// apiProvider = new ApiDataProvider(),
provider = new JsonProvider(),
port = process.env.PORT || 1704,
enviroment = process.env.NODE_ENV || 'local',
app = express();
/////////////////////////////////
// General express server config
app.use(express.json());
app.use(express.urlencoded());
app.use(express.cookieParser());
app.use(express.static(__dirname + '/node_modules'));
app.use(express.static(__dirname + '/public'));
app.use(app.router);
// Serves initial html page
app.get('/', function (req, res) {
res.sendfile(__dirname + '/public/splash.html');
});
app.get('/main', function (req, res) {
res.sendfile(__dirname + '/public/main/main.html');
});
app.get('/highscore', function (req, res) {
res.sendfile(__dirname + '/public/highscore/highscore.html');
});
app.get('/achievements', function (req, res) {
res.sendfile(__dirname + '/public/achievements/achievements.html');
});
app.get('/demo', function (req, res) {
res.sendfile(__dirname + '/public/demo.html');
});
app.get('/api', function (req, res) {
res.sendfile(__dirname + '/public/api.html');
});
// Serves test JSON of meter readings
app.get('/json/mainViewData', function (req, res) {
res.json(provider.mainViewData());
});
app.get('/json/lastWeek', function (req, res) {
res.json(provider.lastWeek());
});
app.get('/json/thisWeek', function (req, res) {
res.json(provider.thisWeek());
});
app.get('/json/lastWeekAwg', function (req, res) {
res.json(provider.lastWeekAwg());
});
app.get('/json/thisWeekAwg', function (req, res) {
res.json(provider.thisWeekAwg());
});
app.get('/json/thisGroupAwg', function (req, res) {
res.json(provider.thisGroupAwg());
});
app.get('/json/achievements', function (req, res) {
res.json(provider.achievementData());
});
app.get('/json/highscore', function (req, res) {
res.json(provider.highscore());
});
// Start server on given port
app.listen(port);
console.log('po\\/\\/er|-|ack started at http://localhost:' + port + '/');
console.log('Updating cashe...');