forked from jargonautical/pollenizeMapNew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
58 lines (51 loc) · 1.55 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
// Dependency Files
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var handlebars = require('express-handlebars');
var passport = require('passport');
var session = require('express-session');
var mongoose = require('mongoose');
//Port Number and Connection String to DB
var port = process.env.PORT || 3000;
var mongoURI = process.env.mongoURI || 'mongodb://localhost:27017/pollenize';
//App settings for public files and json formatting
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static('www'));
//App Settings for Hanblebars Template engine
app.set('view engine', 'hbs');
app.engine('hbs', handlebars({
layoutsDir: __dirname + '/views/layouts',
extname: 'hbs'
}))
//Authenticaton Dependancies and session settings
require('./middleware/passport')(passport);
app.use(
session({
secret: 'pollenizeSecret',
resave: true,
saveUninitialized: true,
cookie: { maxAge: 600000 }
})
);
app.use(passport.initialize());
app.use(passport.session());
//Routes
app.use('/', require('./routes'));
app.use('/admin', require('./routes/admin'));
app.use('/api', require('./routes/api'));
//Initialise DB Conenction
mongoose.connect(mongoURI, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
console.log('Connected to the DB');
})
.catch((err) => {
console.log('Not connected to the DB with err: ' + err);
});
//Initialise HTTP server
app.listen(port, () => {
console.log(`Listening on port ${port}`);
})