@twin.org/api-server-fastify 0.0.3-next.9 → 0.9.0
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/README.md +1 -1
- package/dist/es/fastifySocketIo.js +4 -1
- package/dist/es/fastifySocketIo.js.map +1 -1
- package/dist/es/fastifyWebServer.js +115 -28
- package/dist/es/fastifyWebServer.js.map +1 -1
- package/dist/types/fastifySocketIo.d.ts +4 -0
- package/dist/types/fastifyWebServer.d.ts +14 -3
- package/docs/changelog.md +867 -102
- package/docs/examples.md +37 -1
- package/docs/reference/classes/FastifyWebServer.md +44 -8
- package/docs/reference/interfaces/IFastifyWebServerConfig.md +6 -6
- package/docs/reference/interfaces/IFastifyWebServerConstructorOptions.md +6 -6
- package/locales/.validate-ignore +3 -2
- package/locales/en.json +9 -1
- package/package.json +16 -16
package/docs/examples.md
CHANGED
|
@@ -1 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Server Fastify Examples
|
|
2
|
+
|
|
3
|
+
Use these snippets to build and run the Fastify server with explicit lifecycle control in scripts and integration tests.
|
|
4
|
+
|
|
5
|
+
## FastifyWebServer
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { FastifyWebServer } from '@twin.org/api-server-fastify';
|
|
9
|
+
|
|
10
|
+
const webServer = new FastifyWebServer();
|
|
11
|
+
|
|
12
|
+
await webServer.build(undefined, undefined, undefined, undefined, {
|
|
13
|
+
port: 8080,
|
|
14
|
+
host: '0.0.0.0'
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
await webServer.start();
|
|
18
|
+
const instance = webServer.getInstance();
|
|
19
|
+
|
|
20
|
+
console.log(instance.server.address() !== null); // true
|
|
21
|
+
|
|
22
|
+
await webServer.stop();
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { FastifyWebServer } from '@twin.org/api-server-fastify';
|
|
27
|
+
|
|
28
|
+
const webServer = new FastifyWebServer();
|
|
29
|
+
|
|
30
|
+
await webServer.build(undefined, undefined, undefined, undefined, {
|
|
31
|
+
port: 3000,
|
|
32
|
+
host: '127.0.0.1'
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
await webServer.start();
|
|
36
|
+
await webServer.stop();
|
|
37
|
+
```
|
|
@@ -28,7 +28,7 @@ The options for the server.
|
|
|
28
28
|
|
|
29
29
|
## Properties
|
|
30
30
|
|
|
31
|
-
### CLASS\_NAME
|
|
31
|
+
### CLASS\_NAME {#class_name}
|
|
32
32
|
|
|
33
33
|
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
34
34
|
|
|
@@ -36,7 +36,25 @@ Runtime name for the class.
|
|
|
36
36
|
|
|
37
37
|
## Methods
|
|
38
38
|
|
|
39
|
-
###
|
|
39
|
+
### className() {#classname}
|
|
40
|
+
|
|
41
|
+
> **className**(): `string`
|
|
42
|
+
|
|
43
|
+
Returns the class name of the component.
|
|
44
|
+
|
|
45
|
+
#### Returns
|
|
46
|
+
|
|
47
|
+
`string`
|
|
48
|
+
|
|
49
|
+
The class name of the component.
|
|
50
|
+
|
|
51
|
+
#### Implementation of
|
|
52
|
+
|
|
53
|
+
`IWebServer.className`
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
|
|
57
|
+
### getInstance() {#getinstance}
|
|
40
58
|
|
|
41
59
|
> **getInstance**(): `FastifyInstance`
|
|
42
60
|
|
|
@@ -54,7 +72,7 @@ The web server instance.
|
|
|
54
72
|
|
|
55
73
|
***
|
|
56
74
|
|
|
57
|
-
### build()
|
|
75
|
+
### build() {#build}
|
|
58
76
|
|
|
59
77
|
> **build**(`restRouteProcessors?`, `restRoutes?`, `socketRouteProcessors?`, `socketRoutes?`, `options?`): `Promise`\<`void`\>
|
|
60
78
|
|
|
@@ -96,7 +114,7 @@ Options for building the server.
|
|
|
96
114
|
|
|
97
115
|
`Promise`\<`void`\>
|
|
98
116
|
|
|
99
|
-
|
|
117
|
+
A promise that resolves when the server is fully built and ready to start.
|
|
100
118
|
|
|
101
119
|
#### Implementation of
|
|
102
120
|
|
|
@@ -104,7 +122,7 @@ Nothing.
|
|
|
104
122
|
|
|
105
123
|
***
|
|
106
124
|
|
|
107
|
-
### start()
|
|
125
|
+
### start() {#start}
|
|
108
126
|
|
|
109
127
|
> **start**(): `Promise`\<`void`\>
|
|
110
128
|
|
|
@@ -114,7 +132,7 @@ Start the server.
|
|
|
114
132
|
|
|
115
133
|
`Promise`\<`void`\>
|
|
116
134
|
|
|
117
|
-
|
|
135
|
+
A promise that resolves when the server is listening for connections.
|
|
118
136
|
|
|
119
137
|
#### Implementation of
|
|
120
138
|
|
|
@@ -122,7 +140,7 @@ Nothing.
|
|
|
122
140
|
|
|
123
141
|
***
|
|
124
142
|
|
|
125
|
-
### stop()
|
|
143
|
+
### stop() {#stop}
|
|
126
144
|
|
|
127
145
|
> **stop**(): `Promise`\<`void`\>
|
|
128
146
|
|
|
@@ -132,8 +150,26 @@ Stop the server.
|
|
|
132
150
|
|
|
133
151
|
`Promise`\<`void`\>
|
|
134
152
|
|
|
135
|
-
|
|
153
|
+
A promise that resolves when the server has shut down all connections.
|
|
136
154
|
|
|
137
155
|
#### Implementation of
|
|
138
156
|
|
|
139
157
|
`IWebServer.stop`
|
|
158
|
+
|
|
159
|
+
***
|
|
160
|
+
|
|
161
|
+
### health() {#health}
|
|
162
|
+
|
|
163
|
+
> **health**(): `Promise`\<`IHealth`[]\>
|
|
164
|
+
|
|
165
|
+
Perform a health check on the server by fetching its own root endpoint.
|
|
166
|
+
|
|
167
|
+
#### Returns
|
|
168
|
+
|
|
169
|
+
`Promise`\<`IHealth`[]\>
|
|
170
|
+
|
|
171
|
+
The health status of the server.
|
|
172
|
+
|
|
173
|
+
#### Implementation of
|
|
174
|
+
|
|
175
|
+
`IWebServer.health`
|
|
@@ -4,24 +4,24 @@ The configuration for the Fastify web server.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
### web?
|
|
7
|
+
### web? {#web}
|
|
8
8
|
|
|
9
|
-
> `optional` **web
|
|
9
|
+
> `optional` **web?**: `Partial`\<`FastifyServerOptions`\>
|
|
10
10
|
|
|
11
11
|
The web server options.
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
### socket?
|
|
15
|
+
### socket? {#socket}
|
|
16
16
|
|
|
17
|
-
> `optional` **socket
|
|
17
|
+
> `optional` **socket?**: `Partial`\<`ServerOptions`\>
|
|
18
18
|
|
|
19
19
|
The socket server options.
|
|
20
20
|
|
|
21
21
|
***
|
|
22
22
|
|
|
23
|
-
### includeErrorStack?
|
|
23
|
+
### includeErrorStack? {#includeerrorstack}
|
|
24
24
|
|
|
25
|
-
> `optional` **includeErrorStack
|
|
25
|
+
> `optional` **includeErrorStack?**: `boolean`
|
|
26
26
|
|
|
27
27
|
Include the stack with errors.
|
|
@@ -4,24 +4,24 @@ The options for the Fastify web server constructor.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
### loggingComponentType?
|
|
7
|
+
### loggingComponentType? {#loggingcomponenttype}
|
|
8
8
|
|
|
9
|
-
> `optional` **loggingComponentType
|
|
9
|
+
> `optional` **loggingComponentType?**: `string`
|
|
10
10
|
|
|
11
11
|
The type of the logging component to use, if undefined, no logging will happen.
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
### config?
|
|
15
|
+
### config? {#config}
|
|
16
16
|
|
|
17
|
-
> `optional` **config
|
|
17
|
+
> `optional` **config?**: [`IFastifyWebServerConfig`](IFastifyWebServerConfig.md)
|
|
18
18
|
|
|
19
19
|
Additional configuration for the server.
|
|
20
20
|
|
|
21
21
|
***
|
|
22
22
|
|
|
23
|
-
### mimeTypeProcessors?
|
|
23
|
+
### mimeTypeProcessors? {#mimetypeprocessors}
|
|
24
24
|
|
|
25
|
-
> `optional` **mimeTypeProcessors
|
|
25
|
+
> `optional` **mimeTypeProcessors?**: `IMimeTypeProcessor`[]
|
|
26
26
|
|
|
27
27
|
Additional MIME type processors.
|
package/locales/.validate-ignore
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# Fastify plugin options in fastifySocketIo.ts — not locale keys
|
|
2
|
+
>=5\.x\.x
|
|
3
|
+
socket\.io
|
package/locales/en.json
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
"badRequest": "The web server could not handle the request",
|
|
6
6
|
"noRestProcessors": "You must configure at least one REST processor",
|
|
7
7
|
"noSocketProcessors": "You must configure at least one socket processor",
|
|
8
|
-
"postProcessorError": "There was a failure after in a post processor for route \"{route}\""
|
|
8
|
+
"postProcessorError": "There was a failure after in a post processor for route \"{route}\"",
|
|
9
|
+
"invalidPublicOrigin": "The public origin \"{publicOrigin}\" is not a valid origin URL, it should be in the format \"protocol://host[:port]\"."
|
|
9
10
|
}
|
|
10
11
|
},
|
|
11
12
|
"info": {
|
|
@@ -17,5 +18,12 @@
|
|
|
17
18
|
"restRouteAdded": "Added REST route \"{route}\" \"{method}\"",
|
|
18
19
|
"socketRouteAdded": "Added socket route: handshake path \"{handshakePath}\", namespace \"{namespace}\", event name \"{eventName}\""
|
|
19
20
|
}
|
|
21
|
+
},
|
|
22
|
+
"health": {
|
|
23
|
+
"fastifyWebServer": {
|
|
24
|
+
"description": "Checks if the Web Server is reachable",
|
|
25
|
+
"reachable": "The Web Server is reachable",
|
|
26
|
+
"unreachable": "The Web Server is unreachable"
|
|
27
|
+
}
|
|
20
28
|
}
|
|
21
29
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/api-server-fastify",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Fastify web server integration for exposing API routes with consistent runtime behaviour.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/
|
|
7
|
+
"url": "git+https://github.com/iotaledger/twin-api.git",
|
|
8
8
|
"directory": "packages/api-server-fastify"
|
|
9
9
|
},
|
|
10
10
|
"author": "martyn.janes@iota.org",
|
|
@@ -14,18 +14,18 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@fastify/compress": "
|
|
18
|
-
"@fastify/cors": "11.
|
|
19
|
-
"@twin.org/api-core": "0.0
|
|
20
|
-
"@twin.org/api-models": "0.0
|
|
21
|
-
"@twin.org/api-processors": "0.0
|
|
22
|
-
"@twin.org/context": "
|
|
23
|
-
"@twin.org/core": "
|
|
24
|
-
"@twin.org/logging-models": "next",
|
|
25
|
-
"@twin.org/nameof": "
|
|
26
|
-
"@twin.org/web": "
|
|
27
|
-
"fastify": "5.
|
|
28
|
-
"socket.io": "4.8.
|
|
17
|
+
"@fastify/compress": "9.0.0",
|
|
18
|
+
"@fastify/cors": "11.2.0",
|
|
19
|
+
"@twin.org/api-core": "^0.9.0",
|
|
20
|
+
"@twin.org/api-models": "^0.9.0",
|
|
21
|
+
"@twin.org/api-processors": "^0.9.0",
|
|
22
|
+
"@twin.org/context": "^0.9.0",
|
|
23
|
+
"@twin.org/core": "^0.9.0",
|
|
24
|
+
"@twin.org/logging-models": "^0.9.0-next.1",
|
|
25
|
+
"@twin.org/nameof": "^0.9.0",
|
|
26
|
+
"@twin.org/web": "^0.9.0",
|
|
27
|
+
"fastify": "5.8.5",
|
|
28
|
+
"socket.io": "4.8.3"
|
|
29
29
|
},
|
|
30
30
|
"main": "./dist/es/index.js",
|
|
31
31
|
"types": "./dist/types/index.d.ts",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"api"
|
|
52
52
|
],
|
|
53
53
|
"bugs": {
|
|
54
|
-
"url": "git+https://github.com/
|
|
54
|
+
"url": "git+https://github.com/iotaledger/twin-api/issues"
|
|
55
55
|
},
|
|
56
56
|
"homepage": "https://twindev.org"
|
|
57
57
|
}
|