-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (31 loc) · 1.07 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
const express = require('express')
const mongoose = require('mongoose')
const routes = require('./server/routes')
const session = require('express-session')
const passport = require('passport')
const path = require('path')
const cookieParser = require('cookie-parser');
var MongoStore = require('connect-mongo')(session);
const bodyParser = require('body-parser')
mongoose.connect( process.env.MONGOLAB_URL||'mongodb://localhost:27017/votingapp')
const app = express()
app.use(express.static(path.join(__dirname, 'dist')))
app.use(bodyParser.urlencoded({ extended: false}));
app.use(bodyParser.json());
app.use(cookieParser('keyboard cat'));
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection })
}))
app.use(passport.initialize());
app.use(passport.session())
app.use(routes)
app.route('*').get((req,res)=>{
res.sendFile(path.join(__dirname+'/client/public/index.html'))
})
const port = process.env.PORT||4000
app.listen(port,()=>{
console.log('app listening od port' + port)
})