-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
55 lines (41 loc) · 1.38 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
const express = require('express')
const mongoose = require('mongoose');
const cookieSession = require('cookie-session')
const passport = require('passport')
const bodyParser = require('body-parser')
const profileRoutes = require('./routes/profile-routes')
const authRoutes = require('./routes/routes')
const consumerRoutes = require('./routes/consumer-routes')
const passportSetup = require('./config/passport-setup')
const keys = require('./config/keys')
const User = require('./models/user-models')
const app = express()
mongoose.connect(keys.mongodb.dbURI, () => console.log('Connected to mongodb'))
app.use(cookieSession({
maxAge: 24 * 60 * 60 * 1000,
keys: [keys.session.cookieKey]
}))
app.use(bodyParser.json());
//support parsing of application/x-www-form-urlencoded post data
app.use(bodyParser.urlencoded({ extended: true }));
// initialise passport
app.use(passport.initialize())
app.use(passport.session())
app.set('view engine', 'hbs');
app.use(express.static(__dirname + '/views'))
app.use('/auth', authRoutes)
app.use('/profile', profileRoutes)
app.use('/consumer', consumerRoutes)
app.get('/', (req, res) => {
res.render('home', {user: req.user});
})
app.get('/allshops', (req, res) => {
User.find({})
.then((users) => {
res.send(users)
})
})
const port = process.env.PORT || 3000
app.listen(port, () => {
console.log('Port Up')
})