-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (21 loc) · 860 Bytes
/
index.js
File metadata and controls
27 lines (21 loc) · 860 Bytes
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
const express = require('express')
const parser = require('body-parser')
const services = require('./services')
const handlify = require('./handler')
const userHandler = handlify('users')
const postsHandler = handlify('posts')
const app = express()
// parse aplication/x-www-form-urlencoded
app.use(parser.urlencoded({extended: false }))
// parse aplication/json
app.use(parser.json())
const port = 3000
app.get('/', userHandler(services).get)
app.post('/', userHandler(services).post)
app.put('/:id', userHandler(services).put)
app.delete('/:id', userHandler(services).delete)
app.get('/posts', postsHandler(services).get)
app.post('/posts', postsHandler(services).post)
app.put('/posts/:id', postsHandler(services).put)
app.delete('/posts/:id', postsHandler(services).delete)
app.listen(port, () => console.log(`Example app listening on port ${port}`))