examples/weather/app.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 59
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 37
mnd 2
bc 2
fnc 3
dl 0
loc 59
rs 10
bpm 0.6666
cpm 1.6666
noi 1
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A app.js ➔ customTitle 0 8 3
1
import express      from 'express';
2
import bodyParser   from 'body-parser';
3
import chronicle, { middlewares } from '../../src';
4
import { citiesList, cityShow, cityUpdate, cityCreate, forecastsList, forecastUpdate } from './routes';
5
6
const port = process.env.PORT || 3005;
7
const chr = middlewares.express(chronicle, {
8
    save : {
9
        uniqueFilter : [ 'context.title', 'request.method', 'response.status.code', 'url.path' ],
10
        files        : [ { reporter: 'lite', path: './documentation/api.md' } ]
11
    }
12
});
13
14
chronicle.setConfig({
15
    headers : {
16
        request : {
17
            include  : [ 'authorization' ],
18
            sanitize : {
19
                authorization : () => "'API KEY'"
20
            }
21
        },
22
        response : {
23
            include : []
24
        }
25
    }
26
});
27
28
const app = express();
29
const router = express.Router();
30
31
router.use(bodyParser.json());
32
33
router.get('/cities', chr('Cities', 'Get list of cities'), citiesList);
34
router.get('/cities/:id', chr('Cities', 'Get one city'), cityShow);
35
router.patch('/cities/:id', chr('Cities', 'Update Existing City'), cityUpdate);
36
router.post('/cities', chr('Cities', 'Create new City'), cityCreate);
37
router.patch('/forecasts/:id', chr('Forecasts', 'Update Forecast'), forecastUpdate);
38
39
// Use function in middleware for full controll
40
function customTitle(req) {
41
    return {
42
        group : 'Forecasts',
43
        title : req.query.cityId
44
            ? 'Forecasts for specific city'
45
            : 'Get list of forecasts'
46
    };
47
}
48
49
router.get('/forecasts', chr(customTitle), forecastsList);
50
51
app.use('/api', router);
52
53
export default app;
54
55
if (!process.env.TEST) {
56
    app.listen(port, () => {
57
        console.log(`Weather server is running on ${port}`);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
58
    });
59
}
60