-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
76 lines (66 loc) · 2.19 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
/**
* ==============================================
* Module dependencies.
* ==============================================
*/
var express = require('express'),
path = require('path'),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
http = require('http'),
mongoose = require('mongoose'),
expressValidator = require('express-validator');
/**
* ==============================================
* Initializing system variables.
* ==============================================
*/
var config = require('./server/configs/Database');
var address = process.env.MONGODB_PORT_27017_TCP_ADDR || 'localhost';
var port = process.env.MONGODB_PORT_27017_TCP_PORT || 27017;
mongoose.connect("mongodb://" + address + ":" + port + "/" + config.databaseName);
/**
* ==============================================
* Initializing application.
* ==============================================
*/
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(expressValidator());
app.use(cookieParser());
app.use(methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
/**
* ==============================================
* Initializing models and routes.
* ==============================================
*/
var router = express.Router();
require('./server/modules/feature/FeatureRoutes')(router);
app.use('/api', router);
/**
* ==============================================
* Error handlers.
* ==============================================
*/
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
app.use(function(err, req, res, next) {
res.send(err.status || 500);
});
/**
* ==============================================
* Start application.
* ==============================================
*/
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
console.log('--------------------------------------------------');
console.log('Express server listening on port: ' + server.address().port);
console.log('Node environment: ' + process.env.NODE_ENV);
});