forked from spolyak/act-standards-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.js
53 lines (47 loc) · 1.43 KB
/
web.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
var http = require('http');
var express = require('express');
var app = express();
var apiContext = '/api/rest/v0.1/';
//Load the iniparser module
var iniparser = require('iniparser');
// Read the ini file and populate the content on the config object
var config = iniparser.parseSync('./config.ini');
//mongo setup
var mongoose = require('mongoose/');
var mongourl;
//cloud foundry
if(process.env.VCAP_SERVICES){
var svcs = JSON.parse(process.env.VCAP_SERVICES);
mongourl = svcs['mongodb'][0].credentials.uri;
}
else{
//heroku
if(process.env.MONGOHQ_URL) {
mongourl = process.env.MONGOHQ_URL;
} else {
//running locally or not on cloud foundry
mongourl = 'mongodb://localhost/act-standards-db';
}
}
mongoose.connect(mongourl);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function callback () {
// yay!
});
// Set the view engine
app.set('view engine', 'jade');
// Where to find the view files
app.set('views', './views');
// CSS, JS, images
app.use(express.static('./public'));
// Explicitly add the router middleware
app.use(app.router);
// Add the errorHander middleware
app.use(express.errorHandler());
// add dev level logging
app.use(express.logger('dev'));
var routes = require('./routes')(app,apiContext);
http.createServer(app).listen(process.env.PORT || config.port, function() {
console.log('ACT Standards Server started, mongourl: ' + mongourl);
});