-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (42 loc) · 1.3 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
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');
const Passport = require('passport');
const logger = require('morgan');
const favicon = require('serve-favicon');
const path = require('path');
const app = express();
require('dotenv').config();
// connecting the local database
const { DB_HOST, DB_NAME } = process.env;
const DB_URL = `mongodb://${DB_HOST}:${DB_NAME}@ds137360.mlab.com:37360/kegparty`;
mongoose.Promise = global.Promise;
mongoose.connect(DB_URL);
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.use(favicon(path.join(__dirname, 'public', 'img', 'favicon.ico')));
app.use(logger('dev'));
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// app.use(require('./middleware'));
app.use(cookieSession({
name: 'session',
keys: ['bumpa'],
}));
app.use(require('express-session')({
secret: 'bumpa',
resave: false,
saveUninitialized: false,
}));
app.use(Passport.initialize());
app.use(Passport.session());
app.use(require('./routes'));
// error 404
app.use((req, res) => {
res.status(400);
res.render('404');
});
app.listen(process.env.PORT || 3000);