@twin.org/api-server-fastify 0.0.1-next.23 → 0.0.1-next.25
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/cjs/index.cjs +22 -8
- package/dist/esm/index.mjs +22 -8
- package/docs/changelog.md +1 -1
- package/locales/en.json +2 -1
- package/package.json +3 -3
package/dist/cjs/index.cjs
CHANGED
|
@@ -290,7 +290,7 @@ class FastifyWebServer {
|
|
|
290
290
|
ts: Date.now(),
|
|
291
291
|
source: this.CLASS_NAME,
|
|
292
292
|
message: `${FastifyWebServer._CLASS_NAME_CAMEL_CASE}.socketRouteAdded`,
|
|
293
|
-
data: { route: path }
|
|
293
|
+
data: { route: `/${path}` }
|
|
294
294
|
});
|
|
295
295
|
const socketNamespace = io.of(`/${pathParts[0]}`);
|
|
296
296
|
const topic = pathParts.slice(1).join("/");
|
|
@@ -414,12 +414,13 @@ class FastifyWebServer {
|
|
|
414
414
|
* @param data The incoming data.
|
|
415
415
|
* @internal
|
|
416
416
|
*/
|
|
417
|
-
async handleRequestSocket(socketRouteProcessors, socketRoute, socket, fullPath, emitTopic,
|
|
417
|
+
async handleRequestSocket(socketRouteProcessors, socketRoute, socket, fullPath, emitTopic, request) {
|
|
418
418
|
const httpServerRequest = {
|
|
419
419
|
method: web.HttpMethod.GET,
|
|
420
420
|
url: fullPath,
|
|
421
421
|
query: socket.handshake.query,
|
|
422
|
-
headers: socket.handshake.headers
|
|
422
|
+
headers: socket.handshake.headers,
|
|
423
|
+
body: request.body
|
|
423
424
|
};
|
|
424
425
|
const httpResponse = {};
|
|
425
426
|
const httpRequestIdentity = {};
|
|
@@ -428,7 +429,6 @@ class FastifyWebServer {
|
|
|
428
429
|
};
|
|
429
430
|
delete httpServerRequest.query?.EIO;
|
|
430
431
|
delete httpServerRequest.query?.transport;
|
|
431
|
-
httpServerRequest.body = data;
|
|
432
432
|
await this.runProcessorsSocket(socketRouteProcessors, socketRoute, httpServerRequest, httpResponse, httpRequestIdentity, processorState, emitTopic, async (topic, response) => {
|
|
433
433
|
await socket.emit(topic, response);
|
|
434
434
|
});
|
|
@@ -448,12 +448,26 @@ class FastifyWebServer {
|
|
|
448
448
|
// Custom emit method which will also call the post processors
|
|
449
449
|
const postProcessEmit = async (topic, response, responseProcessorState) => {
|
|
450
450
|
await responseEmitter(topic, response);
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
451
|
+
try {
|
|
452
|
+
// The post processors are called after the response has been emitted
|
|
453
|
+
for (const postSocketRouteProcessor of socketRouteProcessors) {
|
|
454
|
+
if (core.Is.function(postSocketRouteProcessor.post)) {
|
|
455
|
+
await postSocketRouteProcessor.post(httpServerRequest, response, socketRoute, httpRequestIdentity, responseProcessorState);
|
|
456
|
+
}
|
|
455
457
|
}
|
|
456
458
|
}
|
|
459
|
+
catch (err) {
|
|
460
|
+
this._loggingConnector?.log({
|
|
461
|
+
level: "error",
|
|
462
|
+
ts: Date.now(),
|
|
463
|
+
source: this.CLASS_NAME,
|
|
464
|
+
message: `${FastifyWebServer._CLASS_NAME_CAMEL_CASE}.postProcessorError`,
|
|
465
|
+
error: core.BaseError.fromError(err),
|
|
466
|
+
data: {
|
|
467
|
+
route: socketRoute.path
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
}
|
|
457
471
|
};
|
|
458
472
|
try {
|
|
459
473
|
for (const socketRouteProcessor of socketRouteProcessors) {
|
package/dist/esm/index.mjs
CHANGED
|
@@ -288,7 +288,7 @@ class FastifyWebServer {
|
|
|
288
288
|
ts: Date.now(),
|
|
289
289
|
source: this.CLASS_NAME,
|
|
290
290
|
message: `${FastifyWebServer._CLASS_NAME_CAMEL_CASE}.socketRouteAdded`,
|
|
291
|
-
data: { route: path }
|
|
291
|
+
data: { route: `/${path}` }
|
|
292
292
|
});
|
|
293
293
|
const socketNamespace = io.of(`/${pathParts[0]}`);
|
|
294
294
|
const topic = pathParts.slice(1).join("/");
|
|
@@ -412,12 +412,13 @@ class FastifyWebServer {
|
|
|
412
412
|
* @param data The incoming data.
|
|
413
413
|
* @internal
|
|
414
414
|
*/
|
|
415
|
-
async handleRequestSocket(socketRouteProcessors, socketRoute, socket, fullPath, emitTopic,
|
|
415
|
+
async handleRequestSocket(socketRouteProcessors, socketRoute, socket, fullPath, emitTopic, request) {
|
|
416
416
|
const httpServerRequest = {
|
|
417
417
|
method: HttpMethod.GET,
|
|
418
418
|
url: fullPath,
|
|
419
419
|
query: socket.handshake.query,
|
|
420
|
-
headers: socket.handshake.headers
|
|
420
|
+
headers: socket.handshake.headers,
|
|
421
|
+
body: request.body
|
|
421
422
|
};
|
|
422
423
|
const httpResponse = {};
|
|
423
424
|
const httpRequestIdentity = {};
|
|
@@ -426,7 +427,6 @@ class FastifyWebServer {
|
|
|
426
427
|
};
|
|
427
428
|
delete httpServerRequest.query?.EIO;
|
|
428
429
|
delete httpServerRequest.query?.transport;
|
|
429
|
-
httpServerRequest.body = data;
|
|
430
430
|
await this.runProcessorsSocket(socketRouteProcessors, socketRoute, httpServerRequest, httpResponse, httpRequestIdentity, processorState, emitTopic, async (topic, response) => {
|
|
431
431
|
await socket.emit(topic, response);
|
|
432
432
|
});
|
|
@@ -446,12 +446,26 @@ class FastifyWebServer {
|
|
|
446
446
|
// Custom emit method which will also call the post processors
|
|
447
447
|
const postProcessEmit = async (topic, response, responseProcessorState) => {
|
|
448
448
|
await responseEmitter(topic, response);
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
449
|
+
try {
|
|
450
|
+
// The post processors are called after the response has been emitted
|
|
451
|
+
for (const postSocketRouteProcessor of socketRouteProcessors) {
|
|
452
|
+
if (Is.function(postSocketRouteProcessor.post)) {
|
|
453
|
+
await postSocketRouteProcessor.post(httpServerRequest, response, socketRoute, httpRequestIdentity, responseProcessorState);
|
|
454
|
+
}
|
|
453
455
|
}
|
|
454
456
|
}
|
|
457
|
+
catch (err) {
|
|
458
|
+
this._loggingConnector?.log({
|
|
459
|
+
level: "error",
|
|
460
|
+
ts: Date.now(),
|
|
461
|
+
source: this.CLASS_NAME,
|
|
462
|
+
message: `${FastifyWebServer._CLASS_NAME_CAMEL_CASE}.postProcessorError`,
|
|
463
|
+
error: BaseError.fromError(err),
|
|
464
|
+
data: {
|
|
465
|
+
route: socketRoute.path
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
}
|
|
455
469
|
};
|
|
456
470
|
try {
|
|
457
471
|
for (const socketRouteProcessor of socketRouteProcessors) {
|
package/docs/changelog.md
CHANGED
package/locales/en.json
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"restRouteAdded": "Added REST route \"{route}\" \"{method}\"",
|
|
10
10
|
"socketRouteAdded": "Added socket route \"{route}\"",
|
|
11
11
|
"noRestProcessors": "You must configure at least one REST processor",
|
|
12
|
-
"noSocketProcessors": "You must configure at least one socket processor"
|
|
12
|
+
"noSocketProcessors": "You must configure at least one socket processor",
|
|
13
|
+
"postProcessorError": "There was a failure after in a post processor for route \"{route}\""
|
|
13
14
|
}
|
|
14
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/api-server-fastify",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.25",
|
|
4
4
|
"description": "Use Fastify as the core web server for APIs",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@fastify/compress": "8.0.1",
|
|
18
18
|
"@fastify/cors": "10.0.1",
|
|
19
|
-
"@twin.org/api-core": "0.0.1-next.
|
|
20
|
-
"@twin.org/api-models": "0.0.1-next.
|
|
19
|
+
"@twin.org/api-core": "0.0.1-next.25",
|
|
20
|
+
"@twin.org/api-models": "0.0.1-next.25",
|
|
21
21
|
"@twin.org/core": "next",
|
|
22
22
|
"@twin.org/logging-models": "next",
|
|
23
23
|
"@twin.org/nameof": "next",
|