-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
84 lines (74 loc) · 2.42 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var express = require('express')
const app = express()
// var bodyParser = require('body-parser')
// const morgan =require('morgan')
require("dotenv").config({path: '../.env'});
const cors =require('cors')
// const port = 5000
const port = process.env.PORT || 5000;
const cookie_parser=require("cookie-parser")
const mongoose =require('mongoose')
const routes = require('./routes/auth')
const category = require('./routes/category')
const passport = require('passport');
var path = require('path');
app.use(cors())
// const session = require('express-session');
// const cookieSession = require('cookie-session')
// require('./config/passport')(passport)
// app.use('/public',express.static('./uploads'))
app.enable("trust proxy")
// app.use(fileUpload())
// app.use(cors())//avoid inter port communication error
app.use(cors({
origin:"https://lfs-project.herokuapp.com",
credentials: true
}));
app.use(express.static(path.join(__dirname, 'uploads')));
app.use(cookie_parser())
// app.use(bodyParser.urlencoded({ extended: true }));
// app.use(bodyParser.json())
// app.use(bodyParser.urlencoded({ extended: true }));
//Data parsing
app.use(express.json())
// app.use(express.urlencoded({extended:false}))
//Express session
// app.use(session({
// secret:'secret',
// resave:true,
// saveUninitialized:true
// }))
//Passport middleware
app.use(passport.initialize())
app.use(passport.session())
// app.use(cookieSession({
// name:'session',
// keys:['key1','key2']
// }))
// passport.serializeUser(function(user, done) {
// console.log('serialize')
// done(null, user.email);
// });
// passport.deserializeUser(function(id, done) {
// console.log('deserialize')
// User.findById(id, function(err, user) {
// done(err, user);
// });
// });
// mongoose.connect('mongodb+srv://swarupkumar:[email protected]/test',{
// useNewUrlParser: true,
// useUnifiedTopology:true,
// useCreateIndex:true
// })
mongoose.connect(`mongodb+srv://${process.env.MONGO_DB_USER}:${process.env.MONGO_DB_PASSWORD}@cluster0.6kk18.mongodb.net/${process.env.MONGO_DB_DATABASE}?retryWrites=true&w=majority`,{
useNewUrlParser: true,
useUnifiedTopology:true,
useFindAndModify:false,
useCreateIndex:true
})
mongoose.connection.on('connected',()=>{
console.log('Database connected !')
})
app.use('/',routes)
app.use('/',category)
app.listen(port,()=> console.log(`Listening to port ${port} !!`))