-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (47 loc) · 1.4 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
require('dotenv').config();
const express = require('express');
const expressLayouts = require('express-ejs-layouts');
const connectDB = require('./server/config/db');
const session = require('express-session');
const passport = require('passport');
const MongoStore = require('connect-mongo');
const mongoose = require('mongoose');
const app = express();
// Connect to MongoDB
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
});
// Port
const port = 5000 || process.env.PORT ;
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
store: MongoStore.create({ mongoUrl: process.env.MONGO_URI })
}));
//Passport initlization
app.use(passport.initialize());
app.use(passport.session());
//middleware
app.use(express.urlencoded({extended:true}));
app.use(express.json());
//connect to db
connectDB();
//Static Files
app.use(express.static('public'));
//Templating Engine
app.use(expressLayouts);
app.set('layout','./layouts/main');//default layout
app.set('view engine','ejs');
//Routes
app.use('/',require('./server/routes/auth'));
app.use('/',require('./server/routes/index'));
app.use('/',require('./server/routes/dashboard'));
//Handle 404
app.use((req,res)=>{
res.status(404).render('404',{title:'404 Page Not Found'});
});
app.listen(port,()=>{
console.log(`Server is running on port ${port}`);
});