-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
87 lines (73 loc) · 2.01 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
/**
*
* Module Dependencies
*
* */
var express = require('express');
var app = express();
var http = require('http').Server(app);
var path = require('path');
var bodyParser = require('body-parser');
var io = require('socket.io')(http);
var rethinkdb = require("./rethinkDB.js");
var mongoDB = require("./mongoDB.js");
var pgrouting = require("./pgrouting.js");
/**
*
* View engine
*
* */
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(bodyParser.json()); //json as param support
app.use(bodyParser.urlencoded({ extended: false })); //data as param support
app.use(express.static(path.join(__dirname, 'public'))); //Make resources public
app.use('/mapa', express.static('public')); //Make resources public at mapa/css/xxx
app.use(express.static(path.join(__dirname, 'test'))); //Make test directory public... for... testing....
/**
*
* Set rethinkDB and mongoDB as a global resource.
* Somebody please optimize this @_@.
*
* */
app.use( function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
req.rethinkdb = rethinkdb;
req.mongoDB = mongoDB;
req.io = io;
req.pgrouting = pgrouting;
next();
});
/**
*
* Routers controllers
*
* */
var indexRouter = require("./routes/router.js");
var mapaRouter = require("./routes/map.js");
var carRouter = require("./routes/car.js");
app.use("/", indexRouter);
app.use("/mapa", mapaRouter);
app.use("/car", carRouter);
/**
*
* Service Configuration
*
* */
app.set('port', process.env.PORT || 16502);
/**
*
* Start
*
* */
http.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
/**
*
* RethinkDB listener.
* When a change happens in the database it's sent through broadcasting with all the new information to the clients.
*
* */
rethinkdb.listenUpdates(io);
});