@biorate/nestjs-tools 1.24.0 → 1.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nyc_output/{dd6ef4c9-1ffd-446e-8e09-13aa0f3ce477.json → dd20662e-b42a-4eac-b521-e71c885587a7.json} +1 -1
- package/.nyc_output/processinfo/dd20662e-b42a-4eac-b521-e71c885587a7.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/CHANGELOG.md +11 -0
- package/coverage/lcov-report/index.html +1 -1
- package/coverage/lcov-report/src/decorators/auth.ts.html +1 -1
- package/coverage/lcov-report/src/decorators/index.html +1 -1
- package/coverage/lcov-report/src/decorators/index.ts.html +1 -1
- package/coverage/lcov-report/src/decorators/roles.ts.html +1 -1
- package/coverage/lcov-report/src/enums/index.html +1 -1
- package/coverage/lcov-report/src/enums/index.ts.html +1 -1
- package/coverage/lcov-report/src/enums/user.ts.html +1 -1
- package/coverage/lcov-report/src/filters/all-exception-filter.ts.html +1 -1
- package/coverage/lcov-report/src/filters/index.html +1 -1
- package/coverage/lcov-report/src/filters/index.ts.html +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.ts.html +1 -1
- package/coverage/lcov-report/src/interceptors/index.html +1 -1
- package/coverage/lcov-report/src/interceptors/index.ts.html +1 -1
- package/coverage/lcov-report/src/interceptors/routes-interceptor.ts.html +6 -3
- package/coverage/lcov-report/src/middlewares/index.html +4 -4
- package/coverage/lcov-report/src/middlewares/index.ts.html +4 -4
- package/coverage/lcov-report/src/middlewares/proxy-middleware.ts.html +292 -0
- package/coverage/lcov-report/src/middlewares/request-count-middleware.ts.html +172 -0
- package/coverage/lcov-report/src/middlewares/response-time-middleware.ts.html +244 -0
- package/coverage/lcov-report/src/providers/auth.ts.html +1 -1
- package/coverage/lcov-report/src/providers/index.html +1 -1
- package/coverage/lcov-report/src/providers/index.ts.html +1 -1
- package/coverage/lcov-report/src/providers/roles.ts.html +1 -1
- package/coverage/lcov.info +10 -10
- package/dist/src/interceptors/routes-interceptor.js.map +1 -1
- package/dist/src/middlewares/index.js +3 -3
- package/dist/src/middlewares/index.js.map +1 -1
- package/dist/src/middlewares/proxy-middleware.js +70 -0
- package/dist/src/middlewares/proxy-middleware.js.map +1 -0
- package/dist/src/middlewares/request-count-middleware.js +45 -0
- package/dist/src/middlewares/request-count-middleware.js.map +1 -0
- package/dist/src/middlewares/response-time-middleware.js +61 -0
- package/dist/src/middlewares/response-time-middleware.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.d.ts +62 -1
- package/package.json +2 -2
- package/.nyc_output/processinfo/dd6ef4c9-1ffd-446e-8e09-13aa0f3ce477.json +0 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
|
|
2
|
+
<!doctype html>
|
|
3
|
+
<html lang="en">
|
|
4
|
+
|
|
5
|
+
<head>
|
|
6
|
+
<title>Code coverage report for src/middlewares/request-count-middleware.ts</title>
|
|
7
|
+
<meta charset="utf-8" />
|
|
8
|
+
<link rel="stylesheet" href="../../prettify.css" />
|
|
9
|
+
<link rel="stylesheet" href="../../base.css" />
|
|
10
|
+
<link rel="shortcut icon" type="image/x-icon" href="../../favicon.png" />
|
|
11
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
12
|
+
<style type='text/css'>
|
|
13
|
+
.coverage-summary .sorter {
|
|
14
|
+
background-image: url(../../sort-arrow-sprite.png);
|
|
15
|
+
}
|
|
16
|
+
</style>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<div class='wrapper'>
|
|
21
|
+
<div class='pad1'>
|
|
22
|
+
<h1><a href="../../index.html">All files</a> / <a href="index.html">src/middlewares</a> request-count-middleware.ts</h1>
|
|
23
|
+
<div class='clearfix'>
|
|
24
|
+
|
|
25
|
+
<div class='fl pad1y space-right2'>
|
|
26
|
+
<span class="strong">66.66% </span>
|
|
27
|
+
<span class="quiet">Statements</span>
|
|
28
|
+
<span class='fraction'>8/12</span>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<div class='fl pad1y space-right2'>
|
|
33
|
+
<span class="strong">0% </span>
|
|
34
|
+
<span class="quiet">Branches</span>
|
|
35
|
+
<span class='fraction'>0/10</span>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
<div class='fl pad1y space-right2'>
|
|
40
|
+
<span class="strong">0% </span>
|
|
41
|
+
<span class="quiet">Functions</span>
|
|
42
|
+
<span class='fraction'>0/2</span>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<div class='fl pad1y space-right2'>
|
|
47
|
+
<span class="strong">60% </span>
|
|
48
|
+
<span class="quiet">Lines</span>
|
|
49
|
+
<span class='fraction'>6/10</span>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
<p class="quiet">
|
|
55
|
+
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
|
56
|
+
</p>
|
|
57
|
+
<template id="filterTemplate">
|
|
58
|
+
<div class="quiet">
|
|
59
|
+
Filter:
|
|
60
|
+
<input oninput="onInput()" type="search" id="fileSearch">
|
|
61
|
+
</div>
|
|
62
|
+
</template>
|
|
63
|
+
</div>
|
|
64
|
+
<div class='status-line medium'></div>
|
|
65
|
+
<pre><table class="coverage">
|
|
66
|
+
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
|
67
|
+
<a name='L2'></a><a href='#L2'>2</a>
|
|
68
|
+
<a name='L3'></a><a href='#L3'>3</a>
|
|
69
|
+
<a name='L4'></a><a href='#L4'>4</a>
|
|
70
|
+
<a name='L5'></a><a href='#L5'>5</a>
|
|
71
|
+
<a name='L6'></a><a href='#L6'>6</a>
|
|
72
|
+
<a name='L7'></a><a href='#L7'>7</a>
|
|
73
|
+
<a name='L8'></a><a href='#L8'>8</a>
|
|
74
|
+
<a name='L9'></a><a href='#L9'>9</a>
|
|
75
|
+
<a name='L10'></a><a href='#L10'>10</a>
|
|
76
|
+
<a name='L11'></a><a href='#L11'>11</a>
|
|
77
|
+
<a name='L12'></a><a href='#L12'>12</a>
|
|
78
|
+
<a name='L13'></a><a href='#L13'>13</a>
|
|
79
|
+
<a name='L14'></a><a href='#L14'>14</a>
|
|
80
|
+
<a name='L15'></a><a href='#L15'>15</a>
|
|
81
|
+
<a name='L16'></a><a href='#L16'>16</a>
|
|
82
|
+
<a name='L17'></a><a href='#L17'>17</a>
|
|
83
|
+
<a name='L18'></a><a href='#L18'>18</a>
|
|
84
|
+
<a name='L19'></a><a href='#L19'>19</a>
|
|
85
|
+
<a name='L20'></a><a href='#L20'>20</a>
|
|
86
|
+
<a name='L21'></a><a href='#L21'>21</a>
|
|
87
|
+
<a name='L22'></a><a href='#L22'>22</a>
|
|
88
|
+
<a name='L23'></a><a href='#L23'>23</a>
|
|
89
|
+
<a name='L24'></a><a href='#L24'>24</a>
|
|
90
|
+
<a name='L25'></a><a href='#L25'>25</a>
|
|
91
|
+
<a name='L26'></a><a href='#L26'>26</a>
|
|
92
|
+
<a name='L27'></a><a href='#L27'>27</a>
|
|
93
|
+
<a name='L28'></a><a href='#L28'>28</a>
|
|
94
|
+
<a name='L29'></a><a href='#L29'>29</a>
|
|
95
|
+
<a name='L30'></a><a href='#L30'>30</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
|
|
96
|
+
<span class="cline-any cline-yes">1x</span>
|
|
97
|
+
<span class="cline-any cline-neutral"> </span>
|
|
98
|
+
<span class="cline-any cline-yes">1x</span>
|
|
99
|
+
<span class="cline-any cline-yes">1x</span>
|
|
100
|
+
<span class="cline-any cline-neutral"> </span>
|
|
101
|
+
<span class="cline-any cline-neutral"> </span>
|
|
102
|
+
<span class="cline-any cline-yes">1x</span>
|
|
103
|
+
<span class="cline-any cline-neutral"> </span>
|
|
104
|
+
<span class="cline-any cline-neutral"> </span>
|
|
105
|
+
<span class="cline-any cline-neutral"> </span>
|
|
106
|
+
<span class="cline-any cline-neutral"> </span>
|
|
107
|
+
<span class="cline-any cline-neutral"> </span>
|
|
108
|
+
<span class="cline-any cline-yes">1x</span>
|
|
109
|
+
<span class="cline-any cline-neutral"> </span>
|
|
110
|
+
<span class="cline-any cline-neutral"> </span>
|
|
111
|
+
<span class="cline-any cline-no"> </span>
|
|
112
|
+
<span class="cline-any cline-no"> </span>
|
|
113
|
+
<span class="cline-any cline-no"> </span>
|
|
114
|
+
<span class="cline-any cline-neutral"> </span>
|
|
115
|
+
<span class="cline-any cline-neutral"> </span>
|
|
116
|
+
<span class="cline-any cline-neutral"> </span>
|
|
117
|
+
<span class="cline-any cline-neutral"> </span>
|
|
118
|
+
<span class="cline-any cline-neutral"> </span>
|
|
119
|
+
<span class="cline-any cline-neutral"> </span>
|
|
120
|
+
<span class="cline-any cline-neutral"> </span>
|
|
121
|
+
<span class="cline-any cline-no"> </span>
|
|
122
|
+
<span class="cline-any cline-neutral"> </span>
|
|
123
|
+
<span class="cline-any cline-neutral"> </span>
|
|
124
|
+
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">import { Injectable, NestMiddleware } from '@nestjs/common';
|
|
125
|
+
import { counter, Counter } from '@biorate/prometheus';
|
|
126
|
+
import { Request, Response, NextFunction } from 'express';
|
|
127
|
+
import onHeaders from 'on-headers';
|
|
128
|
+
import { RoutesInterceptor } from '../interceptors';
|
|
129
|
+
|
|
130
|
+
@Injectable()
|
|
131
|
+
export class RequestCountMiddleware implements NestMiddleware {
|
|
132
|
+
@counter({
|
|
133
|
+
name: 'http_server_requests_seconds_count',
|
|
134
|
+
help: 'Http server requests count',
|
|
135
|
+
labelNames: ['method', 'url', 'status'],
|
|
136
|
+
})
|
|
137
|
+
private counter: Counter;
|
|
138
|
+
|
|
139
|
+
public <span class="fstat-no" title="function not covered" >use(</span>req: Request, res: Response, next: NextFunction) {
|
|
140
|
+
<span class="cstat-no" title="statement not covered" > onHeaders(res, <span class="fstat-no" title="function not covered" >() =</span>> {</span>
|
|
141
|
+
const route = <span class="cstat-no" title="statement not covered" >RoutesInterceptor.map.get(req);</span>
|
|
142
|
+
<span class="cstat-no" title="statement not covered" > this.counter</span>
|
|
143
|
+
.labels({
|
|
144
|
+
method: req.method,
|
|
145
|
+
url: route?.path ?? (req.baseUrl || req.originalUrl),
|
|
146
|
+
status: res.statusCode,
|
|
147
|
+
})
|
|
148
|
+
.inc();
|
|
149
|
+
});
|
|
150
|
+
<span class="cstat-no" title="statement not covered" > next();</span>
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
</pre></td></tr></table></pre>
|
|
154
|
+
|
|
155
|
+
<div class='push'></div><!-- for sticky footer -->
|
|
156
|
+
</div><!-- /wrapper -->
|
|
157
|
+
<div class='footer quiet pad2 space-top1 center small'>
|
|
158
|
+
Code coverage generated by
|
|
159
|
+
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
160
|
+
at 2023-02-02T07:21:51.640Z
|
|
161
|
+
</div>
|
|
162
|
+
<script src="../../prettify.js"></script>
|
|
163
|
+
<script>
|
|
164
|
+
window.onload = function () {
|
|
165
|
+
prettyPrint();
|
|
166
|
+
};
|
|
167
|
+
</script>
|
|
168
|
+
<script src="../../sorter.js"></script>
|
|
169
|
+
<script src="../../block-navigation.js"></script>
|
|
170
|
+
</body>
|
|
171
|
+
</html>
|
|
172
|
+
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
|
|
2
|
+
<!doctype html>
|
|
3
|
+
<html lang="en">
|
|
4
|
+
|
|
5
|
+
<head>
|
|
6
|
+
<title>Code coverage report for src/middlewares/response-time-middleware.ts</title>
|
|
7
|
+
<meta charset="utf-8" />
|
|
8
|
+
<link rel="stylesheet" href="../../prettify.css" />
|
|
9
|
+
<link rel="stylesheet" href="../../base.css" />
|
|
10
|
+
<link rel="shortcut icon" type="image/x-icon" href="../../favicon.png" />
|
|
11
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
12
|
+
<style type='text/css'>
|
|
13
|
+
.coverage-summary .sorter {
|
|
14
|
+
background-image: url(../../sort-arrow-sprite.png);
|
|
15
|
+
}
|
|
16
|
+
</style>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<div class='wrapper'>
|
|
21
|
+
<div class='pad1'>
|
|
22
|
+
<h1><a href="../../index.html">All files</a> / <a href="index.html">src/middlewares</a> response-time-middleware.ts</h1>
|
|
23
|
+
<div class='clearfix'>
|
|
24
|
+
|
|
25
|
+
<div class='fl pad1y space-right2'>
|
|
26
|
+
<span class="strong">52.38% </span>
|
|
27
|
+
<span class="quiet">Statements</span>
|
|
28
|
+
<span class='fraction'>11/21</span>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<div class='fl pad1y space-right2'>
|
|
33
|
+
<span class="strong">0% </span>
|
|
34
|
+
<span class="quiet">Branches</span>
|
|
35
|
+
<span class='fraction'>0/12</span>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
<div class='fl pad1y space-right2'>
|
|
40
|
+
<span class="strong">0% </span>
|
|
41
|
+
<span class="quiet">Functions</span>
|
|
42
|
+
<span class='fraction'>0/3</span>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<div class='fl pad1y space-right2'>
|
|
47
|
+
<span class="strong">47.36% </span>
|
|
48
|
+
<span class="quiet">Lines</span>
|
|
49
|
+
<span class='fraction'>9/19</span>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
<p class="quiet">
|
|
55
|
+
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
|
56
|
+
</p>
|
|
57
|
+
<template id="filterTemplate">
|
|
58
|
+
<div class="quiet">
|
|
59
|
+
Filter:
|
|
60
|
+
<input oninput="onInput()" type="search" id="fileSearch">
|
|
61
|
+
</div>
|
|
62
|
+
</template>
|
|
63
|
+
</div>
|
|
64
|
+
<div class='status-line medium'></div>
|
|
65
|
+
<pre><table class="coverage">
|
|
66
|
+
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
|
67
|
+
<a name='L2'></a><a href='#L2'>2</a>
|
|
68
|
+
<a name='L3'></a><a href='#L3'>3</a>
|
|
69
|
+
<a name='L4'></a><a href='#L4'>4</a>
|
|
70
|
+
<a name='L5'></a><a href='#L5'>5</a>
|
|
71
|
+
<a name='L6'></a><a href='#L6'>6</a>
|
|
72
|
+
<a name='L7'></a><a href='#L7'>7</a>
|
|
73
|
+
<a name='L8'></a><a href='#L8'>8</a>
|
|
74
|
+
<a name='L9'></a><a href='#L9'>9</a>
|
|
75
|
+
<a name='L10'></a><a href='#L10'>10</a>
|
|
76
|
+
<a name='L11'></a><a href='#L11'>11</a>
|
|
77
|
+
<a name='L12'></a><a href='#L12'>12</a>
|
|
78
|
+
<a name='L13'></a><a href='#L13'>13</a>
|
|
79
|
+
<a name='L14'></a><a href='#L14'>14</a>
|
|
80
|
+
<a name='L15'></a><a href='#L15'>15</a>
|
|
81
|
+
<a name='L16'></a><a href='#L16'>16</a>
|
|
82
|
+
<a name='L17'></a><a href='#L17'>17</a>
|
|
83
|
+
<a name='L18'></a><a href='#L18'>18</a>
|
|
84
|
+
<a name='L19'></a><a href='#L19'>19</a>
|
|
85
|
+
<a name='L20'></a><a href='#L20'>20</a>
|
|
86
|
+
<a name='L21'></a><a href='#L21'>21</a>
|
|
87
|
+
<a name='L22'></a><a href='#L22'>22</a>
|
|
88
|
+
<a name='L23'></a><a href='#L23'>23</a>
|
|
89
|
+
<a name='L24'></a><a href='#L24'>24</a>
|
|
90
|
+
<a name='L25'></a><a href='#L25'>25</a>
|
|
91
|
+
<a name='L26'></a><a href='#L26'>26</a>
|
|
92
|
+
<a name='L27'></a><a href='#L27'>27</a>
|
|
93
|
+
<a name='L28'></a><a href='#L28'>28</a>
|
|
94
|
+
<a name='L29'></a><a href='#L29'>29</a>
|
|
95
|
+
<a name='L30'></a><a href='#L30'>30</a>
|
|
96
|
+
<a name='L31'></a><a href='#L31'>31</a>
|
|
97
|
+
<a name='L32'></a><a href='#L32'>32</a>
|
|
98
|
+
<a name='L33'></a><a href='#L33'>33</a>
|
|
99
|
+
<a name='L34'></a><a href='#L34'>34</a>
|
|
100
|
+
<a name='L35'></a><a href='#L35'>35</a>
|
|
101
|
+
<a name='L36'></a><a href='#L36'>36</a>
|
|
102
|
+
<a name='L37'></a><a href='#L37'>37</a>
|
|
103
|
+
<a name='L38'></a><a href='#L38'>38</a>
|
|
104
|
+
<a name='L39'></a><a href='#L39'>39</a>
|
|
105
|
+
<a name='L40'></a><a href='#L40'>40</a>
|
|
106
|
+
<a name='L41'></a><a href='#L41'>41</a>
|
|
107
|
+
<a name='L42'></a><a href='#L42'>42</a>
|
|
108
|
+
<a name='L43'></a><a href='#L43'>43</a>
|
|
109
|
+
<a name='L44'></a><a href='#L44'>44</a>
|
|
110
|
+
<a name='L45'></a><a href='#L45'>45</a>
|
|
111
|
+
<a name='L46'></a><a href='#L46'>46</a>
|
|
112
|
+
<a name='L47'></a><a href='#L47'>47</a>
|
|
113
|
+
<a name='L48'></a><a href='#L48'>48</a>
|
|
114
|
+
<a name='L49'></a><a href='#L49'>49</a>
|
|
115
|
+
<a name='L50'></a><a href='#L50'>50</a>
|
|
116
|
+
<a name='L51'></a><a href='#L51'>51</a>
|
|
117
|
+
<a name='L52'></a><a href='#L52'>52</a>
|
|
118
|
+
<a name='L53'></a><a href='#L53'>53</a>
|
|
119
|
+
<a name='L54'></a><a href='#L54'>54</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
|
|
120
|
+
<span class="cline-any cline-yes">1x</span>
|
|
121
|
+
<span class="cline-any cline-neutral"> </span>
|
|
122
|
+
<span class="cline-any cline-yes">1x</span>
|
|
123
|
+
<span class="cline-any cline-neutral"> </span>
|
|
124
|
+
<span class="cline-any cline-yes">1x</span>
|
|
125
|
+
<span class="cline-any cline-yes">1x</span>
|
|
126
|
+
<span class="cline-any cline-yes">1x</span>
|
|
127
|
+
<span class="cline-any cline-neutral"> </span>
|
|
128
|
+
<span class="cline-any cline-neutral"> </span>
|
|
129
|
+
<span class="cline-any cline-yes">1x</span>
|
|
130
|
+
<span class="cline-any cline-yes">1x</span>
|
|
131
|
+
<span class="cline-any cline-neutral"> </span>
|
|
132
|
+
<span class="cline-any cline-neutral"> </span>
|
|
133
|
+
<span class="cline-any cline-neutral"> </span>
|
|
134
|
+
<span class="cline-any cline-neutral"> </span>
|
|
135
|
+
<span class="cline-any cline-neutral"> </span>
|
|
136
|
+
<span class="cline-any cline-neutral"> </span>
|
|
137
|
+
<span class="cline-any cline-neutral"> </span>
|
|
138
|
+
<span class="cline-any cline-neutral"> </span>
|
|
139
|
+
<span class="cline-any cline-neutral"> </span>
|
|
140
|
+
<span class="cline-any cline-neutral"> </span>
|
|
141
|
+
<span class="cline-any cline-neutral"> </span>
|
|
142
|
+
<span class="cline-any cline-neutral"> </span>
|
|
143
|
+
<span class="cline-any cline-neutral"> </span>
|
|
144
|
+
<span class="cline-any cline-yes">1x</span>
|
|
145
|
+
<span class="cline-any cline-neutral"> </span>
|
|
146
|
+
<span class="cline-any cline-neutral"> </span>
|
|
147
|
+
<span class="cline-any cline-no"> </span>
|
|
148
|
+
<span class="cline-any cline-no"> </span>
|
|
149
|
+
<span class="cline-any cline-neutral"> </span>
|
|
150
|
+
<span class="cline-any cline-neutral"> </span>
|
|
151
|
+
<span class="cline-any cline-neutral"> </span>
|
|
152
|
+
<span class="cline-any cline-no"> </span>
|
|
153
|
+
<span class="cline-any cline-neutral"> </span>
|
|
154
|
+
<span class="cline-any cline-neutral"> </span>
|
|
155
|
+
<span class="cline-any cline-neutral"> </span>
|
|
156
|
+
<span class="cline-any cline-no"> </span>
|
|
157
|
+
<span class="cline-any cline-no"> </span>
|
|
158
|
+
<span class="cline-any cline-no"> </span>
|
|
159
|
+
<span class="cline-any cline-no"> </span>
|
|
160
|
+
<span class="cline-any cline-no"> </span>
|
|
161
|
+
<span class="cline-any cline-neutral"> </span>
|
|
162
|
+
<span class="cline-any cline-neutral"> </span>
|
|
163
|
+
<span class="cline-any cline-neutral"> </span>
|
|
164
|
+
<span class="cline-any cline-neutral"> </span>
|
|
165
|
+
<span class="cline-any cline-neutral"> </span>
|
|
166
|
+
<span class="cline-any cline-neutral"> </span>
|
|
167
|
+
<span class="cline-any cline-no"> </span>
|
|
168
|
+
<span class="cline-any cline-neutral"> </span>
|
|
169
|
+
<span class="cline-any cline-no"> </span>
|
|
170
|
+
<span class="cline-any cline-neutral"> </span>
|
|
171
|
+
<span class="cline-any cline-neutral"> </span>
|
|
172
|
+
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">import { Injectable, NestMiddleware } from '@nestjs/common';
|
|
173
|
+
import { inject, Types } from '@biorate/inversion';
|
|
174
|
+
import { IConfig } from '@biorate/config';
|
|
175
|
+
import { histogram, Histogram } from '@biorate/prometheus';
|
|
176
|
+
import { Request, Response, NextFunction } from 'express';
|
|
177
|
+
import onHeaders from 'on-headers';
|
|
178
|
+
import { RoutesInterceptor } from '../interceptors';
|
|
179
|
+
import { time } from '@biorate/tools';
|
|
180
|
+
|
|
181
|
+
@Injectable()
|
|
182
|
+
export class ResponseTimeMiddleware implements NestMiddleware {
|
|
183
|
+
@inject(Types.Config) private config: IConfig;
|
|
184
|
+
|
|
185
|
+
private readonly suffix: boolean;
|
|
186
|
+
|
|
187
|
+
private readonly header: string;
|
|
188
|
+
|
|
189
|
+
private readonly digits: number;
|
|
190
|
+
|
|
191
|
+
@histogram({
|
|
192
|
+
name: 'http_server_requests_seconds',
|
|
193
|
+
help: 'Http server requests seconds bucket',
|
|
194
|
+
labelNames: ['method', 'url', 'status'],
|
|
195
|
+
buckets: [5, 10, 20, 50, 100, 300, 500, 1000, 2000, 3000, 5000, 10000],
|
|
196
|
+
})
|
|
197
|
+
private histogram: Histogram;
|
|
198
|
+
|
|
199
|
+
<span class="fstat-no" title="function not covered" > public constructor() {</span>
|
|
200
|
+
<span class="cstat-no" title="statement not covered" > this.suffix = this.config.get<boolean>('app.middleware.ResponseTime.suffix', true);</span>
|
|
201
|
+
<span class="cstat-no" title="statement not covered" > this.header = this.config.get<string>(</span>
|
|
202
|
+
'app.middleware.ResponseTime.header',
|
|
203
|
+
'x-response-time',
|
|
204
|
+
);
|
|
205
|
+
<span class="cstat-no" title="statement not covered" > this.digits = this.config.get<number>('app.middleware.ResponseTime.digits', 3);</span>
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
public <span class="fstat-no" title="function not covered" >use(</span>req: Request, res: Response, next: NextFunction) {
|
|
209
|
+
const diff = <span class="cstat-no" title="statement not covered" >time.diff();</span>
|
|
210
|
+
<span class="cstat-no" title="statement not covered" > onHeaders(res, <span class="fstat-no" title="function not covered" >() =</span>> {</span>
|
|
211
|
+
const time = <span class="cstat-no" title="statement not covered" >diff();</span>
|
|
212
|
+
const route = <span class="cstat-no" title="statement not covered" >RoutesInterceptor.map.get(req);</span>
|
|
213
|
+
<span class="cstat-no" title="statement not covered" > this.histogram</span>
|
|
214
|
+
.labels({
|
|
215
|
+
method: req.method,
|
|
216
|
+
url: route?.path ?? (req.baseUrl || req.originalUrl),
|
|
217
|
+
status: res.statusCode,
|
|
218
|
+
})
|
|
219
|
+
.observe(time);
|
|
220
|
+
<span class="cstat-no" title="statement not covered" > res.setHeader(this.header, time.toFixed(this.digits) + (this.suffix ? 'ms' : ''));</span>
|
|
221
|
+
});
|
|
222
|
+
<span class="cstat-no" title="statement not covered" > next();</span>
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
</pre></td></tr></table></pre>
|
|
226
|
+
|
|
227
|
+
<div class='push'></div><!-- for sticky footer -->
|
|
228
|
+
</div><!-- /wrapper -->
|
|
229
|
+
<div class='footer quiet pad2 space-top1 center small'>
|
|
230
|
+
Code coverage generated by
|
|
231
|
+
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
232
|
+
at 2023-02-02T07:21:51.640Z
|
|
233
|
+
</div>
|
|
234
|
+
<script src="../../prettify.js"></script>
|
|
235
|
+
<script>
|
|
236
|
+
window.onload = function () {
|
|
237
|
+
prettyPrint();
|
|
238
|
+
};
|
|
239
|
+
</script>
|
|
240
|
+
<script src="../../sorter.js"></script>
|
|
241
|
+
<script src="../../block-navigation.js"></script>
|
|
242
|
+
</body>
|
|
243
|
+
</html>
|
|
244
|
+
|
|
@@ -178,7 +178,7 @@ export class AuthGuardProvider implements CanActivate {
|
|
|
178
178
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
179
179
|
Code coverage generated by
|
|
180
180
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
181
|
-
at 2023-02-
|
|
181
|
+
at 2023-02-02T07:21:51.640Z
|
|
182
182
|
</div>
|
|
183
183
|
<script src="../../prettify.js"></script>
|
|
184
184
|
<script>
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
132
132
|
Code coverage generated by
|
|
133
133
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
134
|
-
at 2023-02-
|
|
134
|
+
at 2023-02-02T07:21:51.640Z
|
|
135
135
|
</div>
|
|
136
136
|
<script src="../../prettify.js"></script>
|
|
137
137
|
<script>
|
|
@@ -76,7 +76,7 @@ export * from './auth';
|
|
|
76
76
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
77
77
|
Code coverage generated by
|
|
78
78
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
79
|
-
at 2023-02-
|
|
79
|
+
at 2023-02-02T07:21:51.640Z
|
|
80
80
|
</div>
|
|
81
81
|
<script src="../../prettify.js"></script>
|
|
82
82
|
<script>
|
|
@@ -172,7 +172,7 @@ export class RolesGuardProvider implements CanActivate {
|
|
|
172
172
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
173
173
|
Code coverage generated by
|
|
174
174
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
175
|
-
at 2023-02-
|
|
175
|
+
at 2023-02-02T07:21:51.640Z
|
|
176
176
|
</div>
|
|
177
177
|
<script src="../../prettify.js"></script>
|
|
178
178
|
<script>
|
package/coverage/lcov.info
CHANGED
|
@@ -174,8 +174,8 @@ BRH:0
|
|
|
174
174
|
end_of_record
|
|
175
175
|
TN:
|
|
176
176
|
SF:src/interceptors/routes-interceptor.ts
|
|
177
|
-
FN:
|
|
178
|
-
FN:
|
|
177
|
+
FN:13,(anonymous_1)
|
|
178
|
+
FN:18,(anonymous_2)
|
|
179
179
|
FNF:2
|
|
180
180
|
FNH:0
|
|
181
181
|
FNDA:0,(anonymous_1)
|
|
@@ -183,12 +183,12 @@ FNDA:0,(anonymous_2)
|
|
|
183
183
|
DA:1,1
|
|
184
184
|
DA:2,1
|
|
185
185
|
DA:3,1
|
|
186
|
-
DA:
|
|
187
|
-
DA:12,1
|
|
186
|
+
DA:5,1
|
|
188
187
|
DA:13,1
|
|
189
|
-
DA:
|
|
190
|
-
DA:
|
|
191
|
-
DA:
|
|
188
|
+
DA:14,1
|
|
189
|
+
DA:16,0
|
|
190
|
+
DA:19,0
|
|
191
|
+
DA:28,0
|
|
192
192
|
LF:9
|
|
193
193
|
LH:6
|
|
194
194
|
BRF:0
|
|
@@ -207,7 +207,7 @@ BRF:0
|
|
|
207
207
|
BRH:0
|
|
208
208
|
end_of_record
|
|
209
209
|
TN:
|
|
210
|
-
SF:src/middlewares/proxy.ts
|
|
210
|
+
SF:src/middlewares/proxy-middleware.ts
|
|
211
211
|
FN:36,(anonymous_2)
|
|
212
212
|
FN:40,(anonymous_3)
|
|
213
213
|
FN:49,(anonymous_4)
|
|
@@ -250,7 +250,7 @@ BRF:8
|
|
|
250
250
|
BRH:0
|
|
251
251
|
end_of_record
|
|
252
252
|
TN:
|
|
253
|
-
SF:src/middlewares/request-count.ts
|
|
253
|
+
SF:src/middlewares/request-count-middleware.ts
|
|
254
254
|
FN:16,(anonymous_2)
|
|
255
255
|
FN:17,(anonymous_3)
|
|
256
256
|
FNF:2
|
|
@@ -283,7 +283,7 @@ BRF:10
|
|
|
283
283
|
BRH:0
|
|
284
284
|
end_of_record
|
|
285
285
|
TN:
|
|
286
|
-
SF:src/middlewares/response-time.ts
|
|
286
|
+
SF:src/middlewares/response-time-middleware.ts
|
|
287
287
|
FN:28,(anonymous_2)
|
|
288
288
|
FN:37,(anonymous_3)
|
|
289
289
|
FN:39,(anonymous_4)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes-interceptor.js","sourceRoot":"","sources":["../../../src/interceptors/routes-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,sCAA6C;AAC7C,uCAAyC;AACzC,wDAAyD;
|
|
1
|
+
{"version":3,"file":"routes-interceptor.js","sourceRoot":"","sources":["../../../src/interceptors/routes-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,sCAA6C;AAC7C,uCAAyC;AACzC,wDAAyD;AAEzD,2CAKwB;AAGxB,IAAa,iBAAiB,yBAA9B,MAAa,iBAAiB;IAA9B;QAGmB,cAAS,GAAG,IAAI,gBAAS,EAAE,CAAC;IAc/C,CAAC;IAZQ,SAAS,CAAC,OAAyB,EAAE,IAAiB;QAC3D,mBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,EAAE;YAC7D,IAAI,EAAE,IAAA,iBAAS,EACb,IAAA,YAAI,EACF,GAAG,EACH,IAAI,CAAC,SAAS,CAAC,GAAG,CAAS,yBAAa,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,EAC7D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAS,yBAAa,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAChE,CACF;SACF,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACF,CAAA;AAhBwB,qBAAG,GAAG,IAAI,OAAO,EAA8B,CAAA;AAD3D,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;GACA,iBAAiB,CAiB7B;AAjBY,8CAAiB"}
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./proxy-middleware"), exports);
|
|
18
|
+
__exportStar(require("./request-count-middleware"), exports);
|
|
19
|
+
__exportStar(require("./response-time-middleware"), exports);
|
|
20
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/middlewares/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/middlewares/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,6DAA2C;AAC3C,6DAA2C"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ProxyPrometheusMiddleware = void 0;
|
|
13
|
+
const lodash_1 = require("lodash");
|
|
14
|
+
const http_proxy_middleware_1 = require("http-proxy-middleware");
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
16
|
+
const prometheus_1 = require("@biorate/prometheus");
|
|
17
|
+
const tools_1 = require("@biorate/tools");
|
|
18
|
+
let ProxyPrometheusMiddleware = class ProxyPrometheusMiddleware {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.time = new WeakMap();
|
|
21
|
+
const { onProxyReq, onProxyRes } = (0, lodash_1.pick)(options, 'onProxyReq', 'onProxyRes');
|
|
22
|
+
this.handler = (0, http_proxy_middleware_1.createProxyMiddleware)(Object.assign(Object.assign({}, (0, lodash_1.omit)(options, 'onProxyReq', 'onProxyRes')), { onProxyReq: (proxyReq, req, res, options) => {
|
|
23
|
+
this.time.set(req, { time: tools_1.time.diff() });
|
|
24
|
+
return onProxyReq === null || onProxyReq === void 0 ? void 0 : onProxyReq(proxyReq, req, res, options);
|
|
25
|
+
}, onProxyRes: (proxyRes, req, res) => {
|
|
26
|
+
const diff = this.time.get(req);
|
|
27
|
+
this.counter
|
|
28
|
+
.labels({
|
|
29
|
+
method: req.method,
|
|
30
|
+
url: req.baseUrl,
|
|
31
|
+
status: res.statusCode,
|
|
32
|
+
})
|
|
33
|
+
.inc();
|
|
34
|
+
this.histogram
|
|
35
|
+
.labels({
|
|
36
|
+
method: req.method,
|
|
37
|
+
url: req.baseUrl,
|
|
38
|
+
status: res.statusCode,
|
|
39
|
+
})
|
|
40
|
+
.observe(diff.time());
|
|
41
|
+
return onProxyRes === null || onProxyRes === void 0 ? void 0 : onProxyRes(proxyRes, req, res);
|
|
42
|
+
} }));
|
|
43
|
+
}
|
|
44
|
+
static create(options) {
|
|
45
|
+
return new this(options).handler;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, prometheus_1.counter)({
|
|
50
|
+
name: 'http_proxy_server_requests_seconds_count',
|
|
51
|
+
help: 'Http proxy server requests count',
|
|
52
|
+
labelNames: ['method', 'url', 'status'],
|
|
53
|
+
}),
|
|
54
|
+
__metadata("design:type", Object)
|
|
55
|
+
], ProxyPrometheusMiddleware.prototype, "counter", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, prometheus_1.histogram)({
|
|
58
|
+
name: 'http_proxy_server_requests_seconds',
|
|
59
|
+
help: 'Http proxy server requests seconds bucket',
|
|
60
|
+
labelNames: ['method', 'url', 'status'],
|
|
61
|
+
buckets: [5, 10, 20, 50, 100, 300, 500, 1000, 2000, 3000, 5000, 10000],
|
|
62
|
+
}),
|
|
63
|
+
__metadata("design:type", Object)
|
|
64
|
+
], ProxyPrometheusMiddleware.prototype, "histogram", void 0);
|
|
65
|
+
ProxyPrometheusMiddleware = __decorate([
|
|
66
|
+
(0, common_1.Injectable)(),
|
|
67
|
+
__metadata("design:paramtypes", [Object])
|
|
68
|
+
], ProxyPrometheusMiddleware);
|
|
69
|
+
exports.ProxyPrometheusMiddleware = ProxyPrometheusMiddleware;
|
|
70
|
+
//# sourceMappingURL=proxy-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-middleware.js","sourceRoot":"","sources":["../../../src/middlewares/proxy-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,mCAAoC;AAEpC,iEAA8D;AAE9D,2CAA4C;AAC5C,oDAA6E;AAC7E,0CAAsC;AAGtC,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAwBpC,YAAoB,OAAiB;QAN7B,SAAI,GAAG,IAAI,OAAO,EAAmC,CAAC;QAO5D,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,IAAA,aAAI,EAAC,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;QAC7E,IAAI,CAAC,OAAO,GAAG,IAAA,6CAAqB,kCAC/B,IAAA,aAAI,EAAC,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC,KAC5C,UAAU,EAAE,CACV,QAA4B,EAC5B,GAAY,EACZ,GAAa,EACb,OAAgC,EAChC,EAAE;gBACF,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,YAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBAC1C,OAAO,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAG,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;YACnD,CAAC,EACD,UAAU,EAAE,CAAC,QAA8B,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE;gBAC1E,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBAChC,IAAI,CAAC,OAAO;qBACT,MAAM,CAAC;oBACN,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,GAAG,EAAE,GAAG,CAAC,OAAO;oBAChB,MAAM,EAAE,GAAG,CAAC,UAAU;iBACvB,CAAC;qBACD,GAAG,EAAE,CAAC;gBACT,IAAI,CAAC,SAAS;qBACX,MAAM,CAAC;oBACN,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,GAAG,EAAE,GAAG,CAAC,OAAO;oBAChB,MAAM,EAAE,GAAG,CAAC,UAAU;iBACvB,CAAC;qBACD,OAAO,CAAC,IAAK,CAAC,IAAI,EAAE,CAAC,CAAC;gBACzB,OAAO,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAG,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;YAC1C,CAAC,IACD,CAAC;IACL,CAAC;IApCM,MAAM,CAAC,MAAM,CAAC,OAAiB;QACpC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;IACnC,CAAC;CAmCF,CAAA;AAnDC;IALC,IAAA,oBAAO,EAAC;QACP,IAAI,EAAE,0CAA0C;QAChD,IAAI,EAAE,kCAAkC;QACxC,UAAU,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC;KACxC,CAAC;;0DACuB;AAQzB;IANC,IAAA,sBAAS,EAAC;QACT,IAAI,EAAE,oCAAoC;QAC1C,IAAI,EAAE,2CAA2C;QACjD,UAAU,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC;QACvC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC;KACvE,CAAC;;4DAC2B;AAdlB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;;GACA,yBAAyB,CAyDrC;AAzDY,8DAAyB"}
|