yedra 0.13.11 → 0.13.12
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/dist/routing/app.d.ts +5 -2
- package/dist/routing/app.js +19 -9
- package/package.json +2 -2
package/dist/routing/app.d.ts
CHANGED
|
@@ -15,7 +15,10 @@ export declare class Yedra {
|
|
|
15
15
|
private requestData;
|
|
16
16
|
private readonly metricsEndpoint;
|
|
17
17
|
constructor(options?: {
|
|
18
|
-
metrics:
|
|
18
|
+
metrics: {
|
|
19
|
+
port: number;
|
|
20
|
+
path: string;
|
|
21
|
+
};
|
|
19
22
|
});
|
|
20
23
|
use(path: string, endpoint: RestEndpoint | WsEndpoint | Yedra): Yedra;
|
|
21
24
|
static(dir: string, fallback?: string): Promise<void>;
|
|
@@ -54,6 +57,6 @@ export declare class Yedra {
|
|
|
54
57
|
private matchRestRoute;
|
|
55
58
|
private matchWsRoute;
|
|
56
59
|
private track;
|
|
57
|
-
private
|
|
60
|
+
private generateMetrics;
|
|
58
61
|
}
|
|
59
62
|
export {};
|
package/dist/routing/app.js
CHANGED
|
@@ -151,13 +151,6 @@ export class Yedra {
|
|
|
151
151
|
chunks.push(chunk);
|
|
152
152
|
});
|
|
153
153
|
req.on('end', async () => {
|
|
154
|
-
if (this.metricsEndpoint &&
|
|
155
|
-
req.method === 'GET' &&
|
|
156
|
-
req.url === this.metricsEndpoint) {
|
|
157
|
-
res.writeHead(200);
|
|
158
|
-
res.end(Buffer.from(this.metrics()));
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
154
|
const body = chunks.length > 0 ? Buffer.concat(chunks) : undefined;
|
|
162
155
|
const response = await this.fetch(url, {
|
|
163
156
|
method: req.method,
|
|
@@ -195,8 +188,25 @@ export class Yedra {
|
|
|
195
188
|
}
|
|
196
189
|
});
|
|
197
190
|
server.listen(port, () => {
|
|
198
|
-
console.log(`yedra listening on http://localhost:${port}
|
|
191
|
+
console.log(`yedra listening on http://localhost:${port}`);
|
|
199
192
|
});
|
|
193
|
+
const metricsEndpoint = this.metricsEndpoint;
|
|
194
|
+
if (metricsEndpoint !== undefined) {
|
|
195
|
+
const metricsServer = createHttpServer();
|
|
196
|
+
metricsServer.on('request', (req, res) => {
|
|
197
|
+
if (req.method === 'GET' && req.url === metricsEndpoint.path) {
|
|
198
|
+
res.writeHead(200);
|
|
199
|
+
res.end(this.generateMetrics());
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
res.writeHead(404);
|
|
203
|
+
res.end('Not found');
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
metricsServer.listen(metricsEndpoint.port, () => {
|
|
207
|
+
console.log(`yedra metrics on http://localhost:${metricsEndpoint.port}${metricsEndpoint.path}`);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
200
210
|
return new Context(server);
|
|
201
211
|
}
|
|
202
212
|
static errorResponse(status, errorMessage) {
|
|
@@ -252,7 +262,7 @@ export class Yedra {
|
|
|
252
262
|
duration: data.duration + duration,
|
|
253
263
|
};
|
|
254
264
|
}
|
|
255
|
-
|
|
265
|
+
generateMetrics() {
|
|
256
266
|
return Object.entries(this.requestData)
|
|
257
267
|
.map(([key, data]) => {
|
|
258
268
|
const [method, status] = key.split('-');
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yedra",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.12",
|
|
4
4
|
"repository": "github:0codekit/yedra",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@biomejs/biome": "^1.9.4",
|
|
8
8
|
"@types/bun": "^1.2.4",
|
|
9
|
-
"@types/node": "^22.13.
|
|
9
|
+
"@types/node": "^22.13.10",
|
|
10
10
|
"@types/uuid": "^10.0.0",
|
|
11
11
|
"@types/ws": "^8.18.0",
|
|
12
12
|
"typescript": "^5.8.2"
|