-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (40 loc) · 1.51 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
// The 'main' file. Oversees all parts of the app.
// REQUIRES
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const passport = require('passport');
const flash = require('connect-flash');
const morgan = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const session = require('express-session');
const path = require('path');
const MongoStore = require('connect-mongo')(session);
const redirectToHTTPS = require('express-http-to-https').redirectToHTTPS;
require('./config/passport.js')(passport); // Configure passport
const PORT = process.env.PORT || 80;
// CONFIG
mongoose.connect(process.env.MONGODB_URI);
app.use(redirectToHTTPS()); // Make sure the content is server over https
app.use(morgan('dev'));
app.use(express.static(path.join(__dirname, 'views')));
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.set('view engine', 'ejs');
app.use(session({
secret: process.env.passportSecret,
resave: false,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection }) // To store session data
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
// ROUTES
require('./routes/routes.js')(app); // Routes homepage/map/cache
require('./routes/authenticationRoutes.js')(app, passport); // All routes to do with auth
app.listen(PORT, () => {
console.log(`Listening on ${PORT}`); // Good to go!
});