-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
87 lines (60 loc) · 1.67 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
// API Server
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'development'
}
process.on("uncaughtException", function(error, stack){
console.log("Uncaught Error");
console.log(error.stack);
});
// Server Variables
var express = require('express');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var Conf = require('./conf');
var app = express();
var port = process.env.PORT || 5000;
var Event = require('./util/event');
Event.getByLocation("Round Rock, TX", function(events) {
console.log(JSON.stringify(events, null, 4));
})
// Middlewares
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static(__dirname + '/public'));
app.use(cookieParser());
// Database connection
var mongoose = require('mongoose');
mongoose.connect(Conf.mongo_config.connect_string(), { db: { safe:true } }, function(err){
if (err) {
throw err;
}
else {
console.log('Mongoose Connected');
}
});
mongoose.connection.on("error", function(err){
console.log("Mongoose error:", err);
});
mongoose.connection.on("disconnected", function(){
console.log("Mongoose disconnected!");
});
mongoose.set('debug', true);
// Server configuration
// Development only
if ('development' == app.get('env')) {
console.log('STATE: Development')
mongoose.set('debug', true);
}
// Production only
if ('production' == app.get('env')) {
console.log('STATE: Production')
}
// Api Middlewares
app.use('/api', require('./api-manifest'));
app.get('/', function(req, res){
res.send('base-auth');
});
// Start the server listening
app.listen(port, function(){
console.log('base-auth listening on port', port);
});