forked from rajayush012/sahitya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
68 lines (59 loc) · 1.89 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
60
61
62
63
64
65
66
67
68
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const morgan = require('morgan');
const path = require('path')
const authorRoutes = require('./routes/authors');
const novelRoutes = require('./routes/novels');
const partsRoutes = require('./routes/parts');
const passport = require('passport');
const localStrategy = require('passport-local');
const passportLocalMongoose = require('passport-local-mongoose');
const Author = require('./models/authorModel');
const cors = require('cors');
require('dotenv').config()
mongoose.connect("mongodb+srv://Alaap:[email protected]/test?retryWrites=true",
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
}
,function(err) {
if (err) {
console.log("Database Not Connected", err);
} else {
console.log("Atlas Connected")
}
});
const port = 8000;
const app = express();
app.use(cors());
app.set('view engine','ejs');
app.use(require('express-session')({
secret: "Old Monks",
resave: false,
saveUninitialized: false
}));
app.use(bodyParser.urlencoded({extended: true}));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(__dirname+'/public'));
passport.use(new localStrategy(Author.authenticate()));
passport.serializeUser(Author.serializeUser());
passport.deserializeUser(Author.deserializeUser());
app.use((req,res,next)=>{
res.locals.currentUser = req.user;
next();
});
app.use('/author',authorRoutes);
app.use('/novels',novelRoutes);
app.use('/parts',partsRoutes);
app.use(morgan('dev'));
app.use(express.static(path.join(__dirname,'client', 'build')))
app.get('*',(req,res) => {
res.sendFile(path.join(__dirname,'client', 'build', 'index.html'))
})
app.listen(port, ()=>{
console.log('Server is up on port: ',port);
});