-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (41 loc) · 1.11 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
var Express = require('express')
var knex = require('./db/knex')
var bodyParser = require('body-parser')
var session = require('express-session')
var cors = require('cors')
var items = require('./routes/items')
var users = require('./routes/users')
var auth = require('./routes/auth')
var app = Express()
// express-session configuration
var sess = {
secret: 'keyboard kitty cat',
cookie: {},
saveUninitialized: false,
resave: false
}
require('dotenv').load()
app.use(cors({ origin: 'http://localhost:3030' }))
app.use(bodyParser.urlencoded({ extended: false }))
app.use(session(sess))
// Only allow signed-in users to see this section
app.use('/api/v1/', function(req, res, next) {
console.log('===========user session:', req.session)
if (req.session.user) {
next()
}
else {
req.session.error = 'Access denied'
res.send('Not allowed.')
}
})
app.use('/api/v1/items', items)
app.use('/api/v1/users', users)
app.use('/auth', auth)
app.get('/', function(request, response) {
console.log(request)
response.send('Hey, world!')
})
app.listen(8080, function() {
console.log('Listening on 8080...')
})