-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
54 lines (45 loc) · 1.16 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
//imports
const express = require('express')
//instantiations
const app = express()
const bodyParser = require('body-parser')
app.use(bodyParser.json())
//middleware
app.use((req, res, next) => {
//console.log('{req.method}: ${req.url}')
console.log(`${req.method}: ${req.url}`)
next()
})
app.use((req, res, next) => {
if (req.query.api_key) {
next()
} else {
res.status(401).send({msg: 'Not authorized'})
}
})
//Routes
/*app.get('/accounts', (req, res) => {
console.log(`${req.method}: ${req.url}`)
res.send({msg:'accounts'})
})*/
app.get('/accounts', (req, res, next) => {
console.log('accounts inline middleware! Yahoo!')
next(new Error('Opsss'))
},(req, res) => {
console.log(`${req.method}: ${req.url}`)
res.send({msg:'accounts'})
})
app.post('/transactions', (req, res) => {
console.log('console.log req.body ', req.body)
console.log(`${req.method}: ${req.url}`)
res.send({msg:'res.send transactions. Yahooooooooo! OK'})
})
app.use((error, req, res, next) => {
res.status(500).send(error)
})
/* app.get('/', (req, res) => {
res.send({msg:'hello world!!'})
})
*/
//Bootup
app.listen(3000)