This repository has been archived by the owner on Oct 2, 2019. It is now read-only.
forked from dasavi/stallmonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (39 loc) · 1.41 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
/*----Require Config----*/
var express = require('express');
var app = module.exports = express();
var bodyParser = require('body-parser');
var stallController = require('./custom_modules/stallController');
/*----Configure Express------*/
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/stallmonitor'));
app.use(bodyParser.json());
/*------Start Server-------*/
app.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'));
});
/*--------Routes----------*/
app.get('/', function(request, response) {
response.send('Hello World!');
});
app.get('/stallmonitor', function(request, response) {
response.sendfile('stallmonitor/index.html');
});
app.post('/stall', function(request, response) {
var requestBody = request.body;
console.log("Request Body: " + JSON.stringify(requestBody) );
var floor = requestBody.floor,
bathroom = requestBody.bathroom,
stallName = requestBody.stallName,
occupied = requestBody.occupied;
stallController.updateStallStatus(floor, bathroom, stallName, occupied, response);
});
app.get('/stall', function(request, response) {
var requestBody = request.query;
var floor = requestBody.floor,
bathroom = requestBody.bathroom,
stallName = requestBody.stallName;
var callback = function(val){
response.json({ "occupied": val });;
};
stallController.getStallStatus(floor, bathroom, stallName, callback);
});