-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
74 lines (63 loc) · 1.73 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
67
68
69
70
71
72
73
74
//dependencies
let express = require('express');
let mongoose = require('mongoose');
let bodyParser = require('body-parser');
let exphbs = require('express-handlebars')
var expressValidator = require('express-validator');
let path = require('path');
let app = express();
var cors = require('cors')
app.use(cors())
//db
let db = mongoose.connection;
var promise = mongoose.connect('mongodb://localhost/mango', {
useMongoClient: true,
/* other options */
});
//routes
let routes = require('./routes/index');
let form = require('./routes/form');
let sponsor = require('./routes/sponsor');
let download = require('./routes/download');
let dlresume = require('./routes/dlresume');
//middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Express Validator
app.use(expressValidator({
errorFormatter: function(param, msg, value) {
var namespace = param.split('.')
, root = namespace.shift()
, formParam = root;
while(namespace.length) {
formParam += '[' + namespace.shift() + ']';
}
return {
param : formParam,
msg : msg,
value : value
};
}
}));
// Make our db accessible to our router
app.use(function(req,res,next){
req.db = db;
next();
});
//view
app.set('views', path.join(__dirname, 'views'));
app.engine('handlebars', exphbs({defaultLayout:'layout'}))
app.set('view engine', 'handlebars')
//static
app.use(express.static(path.join(__dirname,'public')));
app.use(express.static('public/img'));
//routes
app.use('/', routes);
app.use('/', form);
app.use('/', sponsor);
app.use('/', download);
app.use('/', dlresume);
//port
var port = process.env.port || 8050;
app.listen(port );
console.log('Listening on port '+ port);