-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
25 lines (19 loc) · 736 Bytes
/
index.js
File metadata and controls
25 lines (19 loc) · 736 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
const logger = require('koa-logger')
const router = require('koa-joi-router');
const Koa = require('koa');
const userController = require('./controllers/user_controller')
const r = router();
const app = new Koa();
const API_PORT = process.env.PORT || '3000';
app.use(logger())
app.use(r.middleware());
r.get('/ping', async ctx => { ctx.body = 'pong'; });
r.get('/users', userController.getUsers)
r.post('/users', { validate: userController.paramsValidation }, userController.createUser)
r.get('/users/:id', userController.showUser)
r.delete('/users/:id', userController.deleteUser)
r.patch('/users/:id', { validate: { type: 'json' } }, userController.updateUser)
const server = app.listen(API_PORT);
module.exports = {
server
};