-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
59 lines (49 loc) · 1.69 KB
/
app.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
56
57
58
59
import express from 'express';
import bodyParser from 'body-parser';
import chronicle, { middlewares } from '../../src';
import { citiesList, cityShow, cityUpdate, cityCreate, forecastsList, forecastUpdate } from './routes';
const port = process.env.PORT || 3005;
const chr = middlewares.express(chronicle, {
save : {
uniqueFilter : [ 'context.title', 'request.method', 'response.status.code', 'url.path' ],
files : [ { reporter: 'lite', path: './documentation/api.md' } ]
}
});
chronicle.setConfig({
headers : {
request : {
include : [ 'authorization' ],
sanitize : {
authorization : () => "'API KEY'"
}
},
response : {
include : []
}
}
});
const app = express();
const router = express.Router();
router.use(bodyParser.json());
router.get('/cities', chr('Cities', 'Get list of cities'), citiesList);
router.get('/cities/:id', chr('Cities', 'Get one city'), cityShow);
router.patch('/cities/:id', chr('Cities', 'Update Existing City'), cityUpdate);
router.post('/cities', chr('Cities', 'Create new City'), cityCreate);
router.patch('/forecasts/:id', chr('Forecasts', 'Update Forecast'), forecastUpdate);
// Use function in middleware for full controll
function customTitle(req) {
return {
group : 'Forecasts',
title : req.query.cityId
? 'Forecasts for specific city'
: 'Get list of forecasts'
};
}
router.get('/forecasts', chr(customTitle), forecastsList);
app.use('/api', router);
export default app;
if (!process.env.TEST) {
app.listen(port, () => {
console.log(`Weather server is running on ${port}`);
});
}