-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
59 lines (48 loc) · 1.51 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
59
// Load express and middleware
const express = require('express');
const path = require('path');
const morgan = require('morgan');
const passport = require('passport');
const methodOverride = require('method-override');
const favicon = require('serve-favicon');
const nodemailer = require('nodemailer');
const port = process.env.PORT || 3000;
// Routes
const indexRouter = require('./routes/index');
const drugsRouter = require('./routes/drugs');
const reviewsRouter = require('./routes/reviews');
const usersRouter = require('./routes/users');
// Create our express app
const app = express();
// Connect to DB, and configs
// Has to be before database config
require('dotenv').config({ path: require('find-config')('.env')})
require('./config/database');
require('./config/passport');
// Setup views
app.set('view engine', 'ejs');
// Mount middleware
app.use(morgan('dev'));
app.use(express.static('public'));
app.use(express.json());
app.use(methodOverride('_method'));
app.use(express.urlencoded({ extended: false }));
app.use(favicon(path.join(__dirname, 'public/img', 'pills.ico')));
// Session middleware
const session = require('express-session');
app.use(session({
secret: 'DRUGS',
resave: false,
saveUninitialized: true
}))
app.use(passport.initialize());
app.use(passport.session());
// Mount Routes
app.use('/', indexRouter);
app.use('/drugs', drugsRouter);
app.use('/', reviewsRouter);
app.use('/users', usersRouter);
// Listening...
app.listen(port, function () {
console.log(`MongoDB is listening on: ${port}`);
});