-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
67 lines (48 loc) · 1.87 KB
/
app.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
var http = require('http');
var express = require('express');
var session = require('express-session');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
// for db connections Now we are taking dabatase as an session
var MongoStore = require('connect-mongo')(session);
// Now express is an framework
var app = express();
app.locals.pretty = true;
// set properties
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/app/server/views');
app.set('view engine', 'pug');
// use
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// stylus is use for styling of text which is use in UI so path of UI
app.use(require('stylus').middleware({ src: __dirname + '/app/public' }));
// set UI Path
app.use(express.static(__dirname + '/app/public'));
// build mongo database connection url //
process.env.DB_HOST = process.env.DB_HOST || 'localhost'
process.env.DB_PORT = process.env.DB_PORT || 27017;
process.env.DB_NAME = process.env.DB_NAME || 'Prostate';
if (app.get('env') != 'live'){
process.env.DB_URL = 'mongodb://'+process.env.DB_HOST+':'+process.env.DB_PORT;
} else {
// prepend url with authentication credentials //
process.env.DB_URL = 'mongodb://'+process.env.DB_USER+':'+process.env.DB_PASS+'@'+process.env.DB_HOST+':'+process.env.DB_PORT;
}
// create Url of db for accessing
app.use(session({
secret: 'faeb4453e5d14fe6f6d04637f78077c76c73d1b4',
proxy: true,
resave: true,
saveUninitialized: true,
store: new MongoStore({ url: process.env.DB_URL })
})
);
// set path for api execution Like rest Api for transfering data
// . represents current dir and after that dir that we want
require('./app/server/routes')(app);
// launch the website
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});