@innet/server 2.0.0-alpha.2 → 2.0.0-alpha.21
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 +1114 -404
- package/example/requests/index.d.ts +1 -1
- package/example/requests/todo/AddTodo/AddTodo.d.ts +1 -0
- package/example/requests/todo/AddTodo/index.d.ts +1 -0
- package/example/requests/todo/DeleteTodo/DeleteTodo.d.ts +1 -0
- package/example/requests/todo/DeleteTodo/index.d.ts +1 -0
- package/example/requests/todo/EditTodo/EditTodo.d.ts +1 -0
- package/example/requests/todo/EditTodo/index.d.ts +1 -0
- package/example/requests/todo/GetTodo/GetTodo.d.ts +1 -0
- package/example/requests/todo/GetTodo/index.d.ts +1 -0
- package/example/requests/todo/GetTodos/GetTodos.d.ts +1 -0
- package/example/requests/todo/GetTodos/index.d.ts +1 -0
- package/example/requests/todo/index.d.ts +5 -0
- package/example/requests/todo/todos.d.ts +1 -0
- package/example/schemas/app/ListQueryParams/ListQueryParams.d.ts +1 -0
- package/example/schemas/app/ListQueryParams/index.d.ts +1 -0
- package/example/schemas/app/ListSchema/ListSchema.d.ts +4 -1
- package/example/schemas/app/index.d.ts +1 -0
- package/example/schemas/index.d.ts +1 -3
- package/example/schemas/todo/TodoSchema/TodoSchema.d.ts +4 -0
- package/example/schemas/todo/TodoSchema/index.d.ts +1 -0
- package/example/schemas/todo/index.d.ts +1 -0
- package/example/tags/Todo/Todo.d.ts +1 -0
- package/example/tags/Todo/index.d.ts +1 -0
- package/example/tags/index.d.ts +1 -1
- package/handler/handler.d.ts +13 -7
- package/handler/handler.es6.js +12 -6
- package/handler/handler.js +12 -6
- package/hooks/index.d.ts +4 -0
- package/hooks/index.es6.js +4 -0
- package/hooks/index.js +4 -0
- package/hooks/useAction/useAction.es6.js +1 -1
- package/hooks/useAction/useAction.js +1 -1
- package/hooks/useApi/useApi.d.ts +1 -3
- package/hooks/useClientIp/index.d.ts +1 -0
- package/hooks/useClientIp/index.es6.js +1 -0
- package/hooks/useClientIp/index.js +9 -0
- package/hooks/useClientIp/useClientIp.d.ts +1 -0
- package/hooks/useClientIp/useClientIp.es6.js +9 -0
- package/hooks/useClientIp/useClientIp.js +13 -0
- package/hooks/useComponentName/useComponentName.d.ts +1 -1
- package/hooks/useEndpoint/useEndpoint.es6.js +3 -1
- package/hooks/useEndpoint/useEndpoint.js +3 -1
- package/hooks/useObjectSchemaContext/index.d.ts +1 -0
- package/hooks/useObjectSchemaContext/index.es6.js +1 -0
- package/hooks/useObjectSchemaContext/index.js +10 -0
- package/hooks/useObjectSchemaContext/useObjectSchemaContext.d.ts +3 -0
- package/hooks/useObjectSchemaContext/useObjectSchemaContext.es6.js +14 -0
- package/hooks/useObjectSchemaContext/useObjectSchemaContext.js +19 -0
- package/hooks/useRequest/index.es6.js +1 -1
- package/hooks/useRequest/index.js +0 -1
- package/hooks/useRequest/useRequest.d.ts +1 -4
- package/hooks/useRequest/useRequest.es6.js +4 -4
- package/hooks/useRequest/useRequest.js +3 -4
- package/hooks/useResponse/index.es6.js +1 -1
- package/hooks/useResponse/index.js +0 -1
- package/hooks/useResponse/useResponse.d.ts +1 -4
- package/hooks/useResponse/useResponse.es6.js +4 -4
- package/hooks/useResponse/useResponse.js +3 -4
- package/hooks/useSchemaType/useSchemaType.d.ts +3 -2
- package/hooks/useSchemaType/useSchemaType.es6.js +2 -3
- package/hooks/useSchemaType/useSchemaType.js +2 -3
- package/hooks/useServer/useServer.d.ts +1 -0
- package/hooks/useServer/useServer.es6.js +3 -1
- package/hooks/useServer/useServer.js +3 -1
- package/hooks/useServerPlugin/index.d.ts +1 -0
- package/hooks/useServerPlugin/index.es6.js +1 -0
- package/hooks/useServerPlugin/index.js +9 -0
- package/hooks/useServerPlugin/useServerPlugin.d.ts +2 -0
- package/hooks/useServerPlugin/useServerPlugin.es6.js +13 -0
- package/hooks/useServerPlugin/useServerPlugin.js +17 -0
- package/hooks/useServerPlugins/index.d.ts +1 -0
- package/hooks/useServerPlugins/index.es6.js +1 -0
- package/hooks/useServerPlugins/index.js +10 -0
- package/hooks/useServerPlugins/useServerPlugins.d.ts +4 -0
- package/hooks/useServerPlugins/useServerPlugins.es6.js +14 -0
- package/hooks/useServerPlugins/useServerPlugins.js +19 -0
- package/index.es6.js +14 -7
- package/index.js +26 -10
- package/package.json +2 -2
- package/plugins/main/api/api.d.ts +2 -0
- package/plugins/main/api/api.es6.js +49 -51
- package/plugins/main/api/api.js +49 -51
- package/plugins/main/endpoint/endpoint.es6.js +4 -1
- package/plugins/main/endpoint/endpoint.js +4 -1
- package/plugins/main/index.d.ts +1 -1
- package/plugins/main/index.es6.js +1 -1
- package/plugins/main/index.js +1 -1
- package/plugins/main/preset/index.d.ts +1 -0
- package/plugins/main/preset/index.es6.js +1 -0
- package/plugins/{utils/prod → main/preset}/index.js +2 -2
- package/plugins/main/preset/preset.d.ts +3 -0
- package/plugins/main/preset/preset.es6.js +13 -0
- package/plugins/{utils/prod/prod.js → main/preset/preset.js} +9 -6
- package/plugins/main/request/request.es6.js +2 -13
- package/plugins/main/request/request.js +2 -13
- package/plugins/main/response/index.es6.js +1 -1
- package/plugins/main/response/index.js +1 -0
- package/plugins/main/response/response.d.ts +6 -2
- package/plugins/main/response/response.es6.js +16 -8
- package/plugins/main/response/response.js +16 -7
- package/plugins/main/server/server.d.ts +3 -3
- package/plugins/main/server/server.es6.js +29 -7
- package/plugins/main/server/server.js +29 -7
- package/plugins/main/tag/tag.es6.js +4 -1
- package/plugins/main/tag/tag.js +4 -1
- package/plugins/request/cms/cms.es6.js +1 -1
- package/plugins/request/cms/cms.js +1 -1
- package/plugins/request/cookie/cookie.es6.js +3 -19
- package/plugins/request/cookie/cookie.js +3 -23
- package/plugins/request/proxy/proxy.d.ts +3 -0
- package/plugins/request/proxy/proxy.es6.js +4 -1
- package/plugins/request/proxy/proxy.js +4 -1
- package/plugins/request/redirect/redirect.d.ts +2 -1
- package/plugins/request/success/success.d.ts +1 -0
- package/plugins/request/success/success.es6.js +13 -4
- package/plugins/request/success/success.js +13 -4
- package/plugins/schema/any/any.d.ts +5 -0
- package/plugins/schema/any/any.es6.js +27 -0
- package/plugins/schema/any/any.js +31 -0
- package/plugins/schema/boolean/boolean.es6.js +2 -4
- package/plugins/schema/boolean/boolean.js +1 -3
- package/plugins/schema/field/field.es6.js +3 -5
- package/plugins/schema/field/field.js +2 -4
- package/plugins/schema/index.d.ts +1 -0
- package/plugins/schema/index.es6.js +1 -0
- package/plugins/schema/index.js +1 -0
- package/plugins/schema/object/object.es6.js +17 -4
- package/plugins/schema/object/object.js +17 -4
- package/plugins/utils/blacklist/blacklist.d.ts +4 -0
- package/plugins/utils/blacklist/blacklist.es6.js +18 -0
- package/plugins/utils/blacklist/blacklist.js +22 -0
- package/plugins/utils/blacklist/index.d.ts +1 -0
- package/plugins/utils/blacklist/index.es6.js +1 -0
- package/plugins/utils/blacklist/index.js +9 -0
- package/plugins/utils/dts/dts.d.ts +3 -3
- package/plugins/utils/dts/dts.es6.js +6 -25
- package/plugins/utils/dts/dts.js +5 -29
- package/plugins/utils/env/env.d.ts +6 -0
- package/plugins/utils/env/env.es6.js +11 -0
- package/plugins/utils/{dev/dev.js → env/env.js} +4 -3
- package/plugins/utils/env/index.d.ts +1 -0
- package/plugins/utils/env/index.es6.js +1 -0
- package/plugins/utils/{dev → env}/index.js +2 -2
- package/plugins/utils/index.d.ts +4 -2
- package/plugins/utils/index.es6.js +4 -2
- package/plugins/utils/index.js +4 -2
- package/plugins/utils/protection/index.d.ts +1 -0
- package/plugins/utils/protection/index.es6.js +1 -0
- package/plugins/utils/protection/index.js +9 -0
- package/plugins/utils/protection/protection.d.ts +8 -0
- package/plugins/utils/protection/protection.es6.js +36 -0
- package/plugins/utils/protection/protection.js +40 -0
- package/plugins/utils/swagger/swagger.es6.js +10 -12
- package/plugins/utils/swagger/swagger.js +10 -12
- package/plugins/utils/whitelist/index.d.ts +1 -0
- package/plugins/utils/whitelist/index.es6.js +1 -0
- package/plugins/utils/whitelist/index.js +9 -0
- package/plugins/utils/whitelist/whitelist.d.ts +4 -0
- package/plugins/utils/whitelist/whitelist.es6.js +20 -0
- package/plugins/utils/whitelist/whitelist.js +24 -0
- package/types.d.ts +2 -10
- package/utils/action/Action.d.ts +7 -4
- package/utils/action/Action.es6.js +35 -11
- package/utils/action/Action.js +36 -12
- package/utils/generateTypes/generateTypes.d.ts +3 -0
- package/utils/generateTypes/generateTypes.es6.js +151 -0
- package/utils/generateTypes/generateTypes.js +156 -0
- package/utils/generateTypes/generateTypes.test.d.ts +1 -0
- package/utils/generateTypes/index.d.ts +1 -0
- package/utils/generateTypes/index.es6.js +1 -0
- package/utils/generateTypes/index.js +10 -0
- package/utils/getEndpoint/getEndpoint.es6.js +2 -2
- package/utils/getEndpoint/getEndpoint.js +2 -2
- package/utils/index.d.ts +1 -0
- package/utils/index.es6.js +1 -0
- package/utils/index.js +1 -0
- package/utils/rules/index.d.ts +0 -1
- package/utils/rules/index.es6.js +0 -1
- package/utils/rules/index.js +0 -1
- package/utils/rules/objectOf/objectOf.d.ts +1 -1
- package/utils/rules/objectOf/objectOf.es6.js +15 -2
- package/utils/rules/objectOf/objectOf.js +15 -2
- package/example/requests/partners/EditPartner/EditPartner.d.ts +0 -1
- package/example/requests/partners/EditPartner/index.d.ts +0 -1
- package/example/requests/partners/GetPartner/GetPartner.d.ts +0 -1
- package/example/requests/partners/GetPartner/index.d.ts +0 -1
- package/example/requests/partners/GetPartners/GetPartners.d.ts +0 -1
- package/example/requests/partners/GetPartners/index.d.ts +0 -1
- package/example/requests/partners/index.d.ts +0 -3
- package/example/schemas/address/AddressSchema/AddressSchema.d.ts +0 -1
- package/example/schemas/address/AddressSchema/index.d.ts +0 -1
- package/example/schemas/address/index.d.ts +0 -1
- package/example/schemas/location/LocationSchema/LocationSchema.d.ts +0 -1
- package/example/schemas/location/LocationSchema/index.d.ts +0 -1
- package/example/schemas/location/index.d.ts +0 -1
- package/example/schemas/partner/EditPartnerSchema/EditPartnerSchema.d.ts +0 -1
- package/example/schemas/partner/EditPartnerSchema/index.d.ts +0 -1
- package/example/schemas/partner/PartnerSchema/PartnerSchema.d.ts +0 -1
- package/example/schemas/partner/PartnerSchema/index.d.ts +0 -1
- package/example/schemas/partner/index.d.ts +0 -2
- package/example/tags/Partner/Partner.d.ts +0 -1
- package/example/tags/Partner/index.d.ts +0 -1
- package/plugins/main/fallback/fallback.d.ts +0 -4
- package/plugins/main/fallback/fallback.es6.js +0 -19
- package/plugins/main/fallback/fallback.js +0 -23
- package/plugins/main/fallback/index.d.ts +0 -1
- package/plugins/main/fallback/index.es6.js +0 -1
- package/plugins/main/fallback/index.js +0 -9
- package/plugins/utils/dev/dev.d.ts +0 -4
- package/plugins/utils/dev/dev.es6.js +0 -10
- package/plugins/utils/dev/index.d.ts +0 -1
- package/plugins/utils/dev/index.es6.js +0 -1
- package/plugins/utils/prod/index.d.ts +0 -1
- package/plugins/utils/prod/index.es6.js +0 -1
- package/plugins/utils/prod/prod.d.ts +0 -4
- package/plugins/utils/prod/prod.es6.js +0 -10
- package/utils/rules/any/any.d.ts +0 -1
- package/utils/rules/any/any.es6.js +0 -5
- package/utils/rules/any/any.js +0 -9
- /package/{utils/rules → plugins/schema}/any/index.d.ts +0 -0
- /package/{utils/rules → plugins/schema}/any/index.es6.js +0 -0
- /package/{utils/rules → plugins/schema}/any/index.js +0 -0
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ Customize
|
|
|
46
46
|
|
|
47
47
|
[← back](#index)
|
|
48
48
|
|
|
49
|
-
The simplest way to start working with `@innet/server`, it is
|
|
49
|
+
The simplest way to start working with `@innet/server`, it is [innetjs](https://www.npmjs.com/package/innetjs) usage.
|
|
50
50
|
|
|
51
51
|
```shell
|
|
52
52
|
npx innetjs init my-app -t api
|
|
@@ -77,6 +77,28 @@ innet(app, server)
|
|
|
77
77
|
|
|
78
78
|
Here is a **Hello World** example:
|
|
79
79
|
|
|
80
|
+
*src/app.tsx*
|
|
81
|
+
```typescript jsx
|
|
82
|
+
export default (
|
|
83
|
+
<server>
|
|
84
|
+
<request>
|
|
85
|
+
<success>
|
|
86
|
+
Hello World!
|
|
87
|
+
</success>
|
|
88
|
+
</request>
|
|
89
|
+
</server>
|
|
90
|
+
)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
*Use `npm start` to run this server.*
|
|
94
|
+
|
|
95
|
+
Open http://localhost:80
|
|
96
|
+
You will see the `Hello Word!` string.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
Here is the simplest [api](#api) example:
|
|
101
|
+
|
|
80
102
|
*src/app.tsx*
|
|
81
103
|
```typescript jsx
|
|
82
104
|
export default (
|
|
@@ -107,7 +129,9 @@ You will see a base Open API JSON structure.
|
|
|
107
129
|
[← back](#index)
|
|
108
130
|
|
|
109
131
|
[\<server>](#server)
|
|
110
|
-
[\<api>](#api)
|
|
132
|
+
[\<api>](#api)
|
|
133
|
+
[\<request>](#request)
|
|
134
|
+
[\<preset>](#preset)
|
|
111
135
|
|
|
112
136
|
---
|
|
113
137
|
|
|
@@ -136,8 +160,8 @@ export default (
|
|
|
136
160
|
```
|
|
137
161
|
|
|
138
162
|
- By default, it uses port `80` for `http` and port `442` for `https`.
|
|
139
|
-
- You can use `
|
|
140
|
-
- [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `
|
|
163
|
+
- You can use `INNET_PORT` environment variable to set it up on CI level.
|
|
164
|
+
- [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `INNET_PORT` in `.env` file of local environment.
|
|
141
165
|
|
|
142
166
|
#### ssl
|
|
143
167
|
|
|
@@ -155,8 +179,8 @@ export default (
|
|
|
155
179
|
)
|
|
156
180
|
```
|
|
157
181
|
|
|
158
|
-
- You can use `
|
|
159
|
-
- [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `
|
|
182
|
+
- You can use `INNET_SSL_KEY` and `INNET_SSL_CRT` environment variables to set it up on CI level.
|
|
183
|
+
- [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `INNET_SSL_KEY` and `INNET_SSL_CRT` in `.env` file.
|
|
160
184
|
- You can add `localhost.key` and `localhost.crt` files in your project folder.
|
|
161
185
|
|
|
162
186
|
#### onStart
|
|
@@ -206,12 +230,25 @@ export default (
|
|
|
206
230
|
)
|
|
207
231
|
```
|
|
208
232
|
|
|
233
|
+
#### onClose
|
|
234
|
+
|
|
235
|
+
Use `onClose` to handle server close action.
|
|
236
|
+
|
|
237
|
+
*src/app.tsx*
|
|
238
|
+
```typescript jsx
|
|
239
|
+
export default (
|
|
240
|
+
<server
|
|
241
|
+
onClose={() => console.log('Close')}
|
|
242
|
+
/>
|
|
243
|
+
)
|
|
244
|
+
```
|
|
245
|
+
|
|
209
246
|
### \<api>
|
|
210
247
|
|
|
211
248
|
[← back](#main)
|
|
212
249
|
|
|
213
|
-
`<api>` element MUST be placed in `<server>` element.
|
|
214
250
|
This element defines a REST API on the server.
|
|
251
|
+
This element MUST be placed in [\<server>](#server) element.
|
|
215
252
|
|
|
216
253
|
#### title
|
|
217
254
|
|
|
@@ -292,7 +329,7 @@ export default (
|
|
|
292
329
|
)
|
|
293
330
|
```
|
|
294
331
|
|
|
295
|
-
*default: 0.0.0
|
|
332
|
+
*default: `INNET_API_VERSION` || `'0.0.0'`*
|
|
296
333
|
|
|
297
334
|
#### prefix
|
|
298
335
|
|
|
@@ -309,6 +346,162 @@ export default (
|
|
|
309
346
|
)
|
|
310
347
|
```
|
|
311
348
|
|
|
349
|
+
#### include
|
|
350
|
+
|
|
351
|
+
A regular expression scopes the API.
|
|
352
|
+
|
|
353
|
+
*src/app.tsx*
|
|
354
|
+
```typescript jsx
|
|
355
|
+
export default (
|
|
356
|
+
<server>
|
|
357
|
+
<api
|
|
358
|
+
include={/^\/(api|openapi)/}
|
|
359
|
+
/>
|
|
360
|
+
</server>
|
|
361
|
+
)
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
#### exclude
|
|
365
|
+
|
|
366
|
+
A regular expression does not scope the API.
|
|
367
|
+
|
|
368
|
+
*src/app.tsx*
|
|
369
|
+
```typescript jsx
|
|
370
|
+
export default (
|
|
371
|
+
<server>
|
|
372
|
+
<api prefix='/api' />
|
|
373
|
+
<api prefix='/openapi' />
|
|
374
|
+
<api exclude={/^\/(api|openapi)/} />
|
|
375
|
+
</server>
|
|
376
|
+
)
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### \<request>
|
|
380
|
+
|
|
381
|
+
[← back](#main)
|
|
382
|
+
|
|
383
|
+
This element MUST be placed in [\<server>](#server) element.
|
|
384
|
+
It defines run-time call handler for parent element.
|
|
385
|
+
|
|
386
|
+
*src/app.tsx*
|
|
387
|
+
```typescript jsx
|
|
388
|
+
export default (
|
|
389
|
+
<server>
|
|
390
|
+
<request>
|
|
391
|
+
<error status={404} />
|
|
392
|
+
</request>
|
|
393
|
+
</server>
|
|
394
|
+
)
|
|
395
|
+
```
|
|
396
|
+
*Any request returns 404*
|
|
397
|
+
|
|
398
|
+
Place [\<request>](#request) in [\<api>](#api) to handle any unknown request in the [\<api>](#api).
|
|
399
|
+
|
|
400
|
+
*src/app.tsx*
|
|
401
|
+
```typescript jsx
|
|
402
|
+
export default (
|
|
403
|
+
<server>
|
|
404
|
+
<api>
|
|
405
|
+
<request>
|
|
406
|
+
<error status={404} />
|
|
407
|
+
</request>
|
|
408
|
+
</api>
|
|
409
|
+
</server>
|
|
410
|
+
)
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
Place [\<request>](#request) in [\<endpoint>](#endpoint) to handle the [\<endpoint>](#endpoint) request.
|
|
414
|
+
|
|
415
|
+
*src/app.tsx*
|
|
416
|
+
```typescript jsx
|
|
417
|
+
export default (
|
|
418
|
+
<server>
|
|
419
|
+
<api>
|
|
420
|
+
<endpoint method='get' path='/my-endpoint'>
|
|
421
|
+
<request>
|
|
422
|
+
<success>
|
|
423
|
+
My Endpoint
|
|
424
|
+
</success>
|
|
425
|
+
</request>
|
|
426
|
+
</endpoint>
|
|
427
|
+
</api>
|
|
428
|
+
<request>
|
|
429
|
+
<success>
|
|
430
|
+
Any other request
|
|
431
|
+
</success>
|
|
432
|
+
</request>
|
|
433
|
+
</server>
|
|
434
|
+
)
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
You can place a component inside [\<request>](#request).
|
|
438
|
+
The component will run when the request will be triggered.
|
|
439
|
+
|
|
440
|
+
*src/app.tsx*
|
|
441
|
+
```typescript jsx
|
|
442
|
+
import { GetPartners } from './GetPartners'
|
|
443
|
+
|
|
444
|
+
export default (
|
|
445
|
+
<server>
|
|
446
|
+
<api>
|
|
447
|
+
<endpoint method='get' path='/partners'>
|
|
448
|
+
<request>
|
|
449
|
+
<GetPartners />
|
|
450
|
+
</request>
|
|
451
|
+
</endpoint>
|
|
452
|
+
</api>
|
|
453
|
+
</server>
|
|
454
|
+
)
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
*src/GetPartners.tsx*
|
|
458
|
+
```typescript jsx
|
|
459
|
+
export const GetPartners = () => (
|
|
460
|
+
<success>
|
|
461
|
+
{{partners: []}}
|
|
462
|
+
</success>
|
|
463
|
+
)
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
### \<preset>
|
|
467
|
+
|
|
468
|
+
[← back](#main)
|
|
469
|
+
|
|
470
|
+
`<preset>` element MUST be placed in `<server>` element.
|
|
471
|
+
This element adds handling of each request.
|
|
472
|
+
|
|
473
|
+
*src/app.tsx*
|
|
474
|
+
```typescript jsx
|
|
475
|
+
export default (
|
|
476
|
+
<server>
|
|
477
|
+
<preset>
|
|
478
|
+
<header
|
|
479
|
+
key='Test'
|
|
480
|
+
value='Ok'
|
|
481
|
+
/>
|
|
482
|
+
</preset>
|
|
483
|
+
</server>
|
|
484
|
+
)
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
Place the element inside [\<api>](#api) to preset it on the api requests scope.
|
|
488
|
+
|
|
489
|
+
*src/app.tsx*
|
|
490
|
+
```typescript jsx
|
|
491
|
+
export default (
|
|
492
|
+
<server>
|
|
493
|
+
<api prefix='/api'>
|
|
494
|
+
<preset>
|
|
495
|
+
<header
|
|
496
|
+
key='Cache-Control'
|
|
497
|
+
value='no-cache, no-store, must-revalidate'
|
|
498
|
+
/>
|
|
499
|
+
</preset>
|
|
500
|
+
</api>
|
|
501
|
+
</server>
|
|
502
|
+
)
|
|
503
|
+
```
|
|
504
|
+
|
|
312
505
|
## Utils
|
|
313
506
|
|
|
314
507
|
This section contains elements of utils.
|
|
@@ -316,102 +509,399 @@ This section contains elements of utils.
|
|
|
316
509
|
[← back](#index)
|
|
317
510
|
|
|
318
511
|
[\<swagger>](#swagger)
|
|
319
|
-
[\<
|
|
320
|
-
[\<dts>](#dts)
|
|
512
|
+
[\<env>](#env)
|
|
513
|
+
[\<dts>](#dts)
|
|
514
|
+
[\<blacklist>](#blacklist)
|
|
515
|
+
[\<whitelist>](#whitelist)
|
|
516
|
+
[\<protection>](#protection)
|
|
321
517
|
|
|
322
518
|
---
|
|
323
519
|
|
|
324
|
-
### \<swagger>
|
|
520
|
+
### \<swagger>
|
|
521
|
+
|
|
522
|
+
[← back](#utils)
|
|
523
|
+
|
|
524
|
+
Use `<swagger>` element to add Swagger UI documentation.
|
|
525
|
+
`<swagger>` element MUST be placed in `<api>` element.
|
|
526
|
+
|
|
527
|
+
*src/app.tsx*
|
|
528
|
+
```typescript jsx
|
|
529
|
+
export default (
|
|
530
|
+
<server>
|
|
531
|
+
<api>
|
|
532
|
+
<swagger />
|
|
533
|
+
</api>
|
|
534
|
+
</server>
|
|
535
|
+
)
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
Open http://localhost:80/swagger-ui
|
|
539
|
+
You will see Swagger UI documentation.
|
|
540
|
+
|
|
541
|
+
You can change the Swagger UI URL path by `path` property of `<swagger>` element.
|
|
542
|
+
|
|
543
|
+
*src/app.tsx*
|
|
544
|
+
```typescript jsx
|
|
545
|
+
export default (
|
|
546
|
+
<server>
|
|
547
|
+
<api>
|
|
548
|
+
<swagger path='/swagger' />
|
|
549
|
+
</api>
|
|
550
|
+
</server>
|
|
551
|
+
)
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
### \<env>
|
|
555
|
+
|
|
556
|
+
[← back](#utils)
|
|
557
|
+
|
|
558
|
+
This element helps to control content by `process.env`.
|
|
559
|
+
|
|
560
|
+
There are a required field of `is`.
|
|
561
|
+
If it's a `string` then an environment variable must be equal to the `string`.
|
|
562
|
+
If it's an `array of string` then an environment variable must be included into the `array of string`.
|
|
563
|
+
|
|
564
|
+
*src/app.tsx*
|
|
565
|
+
```typescript jsx
|
|
566
|
+
export default (
|
|
567
|
+
<server>
|
|
568
|
+
<api>
|
|
569
|
+
<env is='dev'>
|
|
570
|
+
<swagger />
|
|
571
|
+
</env>
|
|
572
|
+
</api>
|
|
573
|
+
</server>
|
|
574
|
+
)
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
*The `<swagger />` will work only if `NODE_ENV` equals `dev`*
|
|
578
|
+
|
|
579
|
+
#### of
|
|
580
|
+
|
|
581
|
+
By default `of` equals `NODE_ENV`. You can check eny other environment variable.
|
|
582
|
+
|
|
583
|
+
*src/app.tsx*
|
|
584
|
+
```typescript jsx
|
|
585
|
+
export default (
|
|
586
|
+
<server>
|
|
587
|
+
<api>
|
|
588
|
+
<env
|
|
589
|
+
of='PORT'
|
|
590
|
+
is={[
|
|
591
|
+
'3000',
|
|
592
|
+
'8080',
|
|
593
|
+
]}>
|
|
594
|
+
<swagger />
|
|
595
|
+
</env>
|
|
596
|
+
</api>
|
|
597
|
+
</server>
|
|
598
|
+
)
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
### \<dts>
|
|
602
|
+
|
|
603
|
+
[← back](#utils)
|
|
604
|
+
|
|
605
|
+
Use `<dts>` element to add types generation.
|
|
606
|
+
`<dts>` element MUST be placed in `<api>` element.
|
|
607
|
+
|
|
608
|
+
*src/app.tsx*
|
|
609
|
+
```typescript jsx
|
|
610
|
+
export default (
|
|
611
|
+
<server>
|
|
612
|
+
<api>
|
|
613
|
+
<dts />
|
|
614
|
+
</api>
|
|
615
|
+
</server>
|
|
616
|
+
)
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
You do not need to import types, use `Api` namespace everywhere.
|
|
620
|
+
Here is an example of generated types usage.
|
|
621
|
+
|
|
622
|
+
```typescript jsx
|
|
623
|
+
import { useParams } from '@innet/server'
|
|
624
|
+
|
|
625
|
+
import { todos } from '../todos'
|
|
626
|
+
|
|
627
|
+
export function DeleteTodo () {
|
|
628
|
+
const { todoId } = useParams<Api.Endpoints['DELETE:/todos/{todoId}']['Params']>()
|
|
629
|
+
|
|
630
|
+
const todoIndex = todos.findIndex(({ id }) => id === todoId)
|
|
631
|
+
|
|
632
|
+
if (todoIndex === -1) {
|
|
633
|
+
return <error code='todoNotFound' status={404} />
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
todos.splice(todoIndex, 1)
|
|
637
|
+
|
|
638
|
+
return <success />
|
|
639
|
+
}
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
#### path
|
|
643
|
+
|
|
644
|
+
This is a path of api TypeScript types file, `<dts>` generates it.
|
|
645
|
+
`'src/api.d.ts'` by default.
|
|
646
|
+
|
|
647
|
+
*src/app.tsx*
|
|
648
|
+
```typescript jsx
|
|
649
|
+
export default (
|
|
650
|
+
<server>
|
|
651
|
+
<api>
|
|
652
|
+
<dts path='src/types.d.ts' />
|
|
653
|
+
</api>
|
|
654
|
+
</server>
|
|
655
|
+
)
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
#### namespace
|
|
659
|
+
|
|
660
|
+
This prop changes namespace for generated types. `'Api'` by default.
|
|
661
|
+
|
|
662
|
+
*src/app.tsx*
|
|
663
|
+
```typescript jsx
|
|
664
|
+
export default (
|
|
665
|
+
<server>
|
|
666
|
+
<api>
|
|
667
|
+
<dts namespace='API' />
|
|
668
|
+
</api>
|
|
669
|
+
</server>
|
|
670
|
+
)
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
### \<blacklist>
|
|
674
|
+
|
|
675
|
+
This element MUST be placed in `<api>` element.
|
|
676
|
+
|
|
677
|
+
[← back](#utils)
|
|
678
|
+
|
|
679
|
+
This element returns own content for a user from IPs list.
|
|
680
|
+
|
|
681
|
+
*src/app.tsx*
|
|
682
|
+
```typescript jsx
|
|
683
|
+
export default (
|
|
684
|
+
<server>
|
|
685
|
+
<api>
|
|
686
|
+
<blacklist>
|
|
687
|
+
<error />
|
|
688
|
+
</blacklist>
|
|
689
|
+
</api>
|
|
690
|
+
</server>
|
|
691
|
+
)
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
#### ip
|
|
695
|
+
|
|
696
|
+
`ip` prop sets black IPs. By default, it equals `INNET_BLACKLIST_IP` node environment variable.
|
|
697
|
+
|
|
698
|
+
You can split IPs by `,` char.
|
|
699
|
+
|
|
700
|
+
*src/app.tsx*
|
|
701
|
+
```typescript jsx
|
|
702
|
+
export default (
|
|
703
|
+
<server>
|
|
704
|
+
<api>
|
|
705
|
+
<blacklist
|
|
706
|
+
ip='0.1.2.3,3.2.1.0'>
|
|
707
|
+
<error />
|
|
708
|
+
</blacklist>
|
|
709
|
+
</api>
|
|
710
|
+
</server>
|
|
711
|
+
)
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
### \<whitelist>
|
|
715
|
+
|
|
716
|
+
This element MUST be placed in `<api>` element.
|
|
717
|
+
|
|
718
|
+
[← back](#utils)
|
|
719
|
+
|
|
720
|
+
This element returns own content for a user IP, which is not in a list.
|
|
721
|
+
|
|
722
|
+
*src/app.tsx*
|
|
723
|
+
```typescript jsx
|
|
724
|
+
export default (
|
|
725
|
+
<server>
|
|
726
|
+
<api>
|
|
727
|
+
<whitelist>
|
|
728
|
+
<error />
|
|
729
|
+
</whitelist>
|
|
730
|
+
</api>
|
|
731
|
+
</server>
|
|
732
|
+
)
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
#### ip
|
|
736
|
+
|
|
737
|
+
`ip` prop sets white IPs. By default, it equals `INNET_WHITELIST_IP` node environment variable.
|
|
738
|
+
|
|
739
|
+
You can split IPs by `,` char.
|
|
740
|
+
|
|
741
|
+
*src/app.tsx*
|
|
742
|
+
```typescript jsx
|
|
743
|
+
export default (
|
|
744
|
+
<server>
|
|
745
|
+
<api>
|
|
746
|
+
<whitelist
|
|
747
|
+
ip='0.1.2.3,3.2.1.0'>
|
|
748
|
+
<error />
|
|
749
|
+
</whitelist>
|
|
750
|
+
</api>
|
|
751
|
+
</server>
|
|
752
|
+
)
|
|
753
|
+
```
|
|
754
|
+
|
|
755
|
+
### \<protection>
|
|
756
|
+
|
|
757
|
+
This element MUST be placed in `<api>` element.
|
|
758
|
+
|
|
759
|
+
[← back](#utils)
|
|
760
|
+
|
|
761
|
+
This element adds protection page.
|
|
762
|
+
You can use it when you want to protect your application.
|
|
763
|
+
|
|
764
|
+
If protection failed content of the element should be used.
|
|
765
|
+
|
|
766
|
+
*src/app.tsx*
|
|
767
|
+
```typescript jsx
|
|
768
|
+
export default (
|
|
769
|
+
<server>
|
|
770
|
+
<api>
|
|
771
|
+
<protection>
|
|
772
|
+
<error
|
|
773
|
+
code='protection'
|
|
774
|
+
status='forbidden'
|
|
775
|
+
/>
|
|
776
|
+
</protection>
|
|
777
|
+
</api>
|
|
778
|
+
</server>
|
|
779
|
+
)
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
#### value
|
|
325
783
|
|
|
326
|
-
|
|
784
|
+
This prop is a secret string of protection value.
|
|
785
|
+
User must provide a protection query param equals the `value`.
|
|
327
786
|
|
|
328
|
-
|
|
329
|
-
|
|
787
|
+
By default, the value is `undefined` and protection does not work.
|
|
788
|
+
You can use `PROTECTION` env to set default protection `value`.
|
|
330
789
|
|
|
331
790
|
*src/app.tsx*
|
|
332
791
|
```typescript jsx
|
|
333
792
|
export default (
|
|
334
793
|
<server>
|
|
335
794
|
<api>
|
|
336
|
-
<
|
|
795
|
+
<protection value='secret'>
|
|
796
|
+
<error
|
|
797
|
+
code='protection'
|
|
798
|
+
status='forbidden'
|
|
799
|
+
/>
|
|
800
|
+
</protection>
|
|
337
801
|
</api>
|
|
338
802
|
</server>
|
|
339
803
|
)
|
|
340
804
|
```
|
|
341
805
|
|
|
342
|
-
|
|
343
|
-
You will see Swagger UI documentation.
|
|
806
|
+
#### maxAge
|
|
344
807
|
|
|
345
|
-
|
|
808
|
+
This prop sets how much time protection is qualified.
|
|
809
|
+
|
|
810
|
+
By default, the prop equals a year.
|
|
811
|
+
You can use `INNET_PROTECTION_MAX_AGE` env to set default `maxAge`.
|
|
346
812
|
|
|
347
813
|
*src/app.tsx*
|
|
348
814
|
```typescript jsx
|
|
349
815
|
export default (
|
|
350
816
|
<server>
|
|
351
817
|
<api>
|
|
352
|
-
<
|
|
818
|
+
<protection
|
|
819
|
+
maxAge={24 * 60 * 60}
|
|
820
|
+
value='secret'>
|
|
821
|
+
<error
|
|
822
|
+
code='protection'
|
|
823
|
+
status='forbidden'
|
|
824
|
+
/>
|
|
825
|
+
</protection>
|
|
353
826
|
</api>
|
|
354
827
|
</server>
|
|
355
828
|
)
|
|
356
829
|
```
|
|
357
830
|
|
|
358
|
-
|
|
831
|
+
#### excludeIp
|
|
359
832
|
|
|
360
|
-
|
|
833
|
+
This prop sets a list of IP addresses (split by `,`) to ignore the protection.
|
|
361
834
|
|
|
362
|
-
|
|
835
|
+
You can use `INNET_PROTECTED_IP` env to set default `excludeIp`.
|
|
363
836
|
|
|
364
837
|
*src/app.tsx*
|
|
365
838
|
```typescript jsx
|
|
366
839
|
export default (
|
|
367
840
|
<server>
|
|
368
841
|
<api>
|
|
369
|
-
<
|
|
370
|
-
|
|
371
|
-
|
|
842
|
+
<protection
|
|
843
|
+
excludeIp='0.0.0.0,127.0.0.0'
|
|
844
|
+
value='secret'>
|
|
845
|
+
<error
|
|
846
|
+
code='protection'
|
|
847
|
+
status='forbidden'
|
|
848
|
+
/>
|
|
849
|
+
</protection>
|
|
372
850
|
</api>
|
|
373
851
|
</server>
|
|
374
852
|
)
|
|
375
853
|
```
|
|
376
854
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
[← back](#utils)
|
|
855
|
+
#### cookieKey
|
|
380
856
|
|
|
381
|
-
|
|
382
|
-
`<dts>` element MUST be placed in `<api>` element.
|
|
857
|
+
This prop sets a cookie field name used to store protection of a user.
|
|
383
858
|
|
|
384
|
-
|
|
859
|
+
By default, it equals `protection`.
|
|
860
|
+
You can use `INNET_PROTECTION_COOKIE_KEY` env to set default `cookieKey`.
|
|
385
861
|
|
|
386
862
|
*src/app.tsx*
|
|
387
863
|
```typescript jsx
|
|
388
864
|
export default (
|
|
389
865
|
<server>
|
|
390
866
|
<api>
|
|
391
|
-
<
|
|
392
|
-
|
|
393
|
-
|
|
867
|
+
<protection
|
|
868
|
+
cookieKey='secret'
|
|
869
|
+
value='secret'>
|
|
870
|
+
<error
|
|
871
|
+
code='protection'
|
|
872
|
+
status='forbidden'
|
|
873
|
+
/>
|
|
874
|
+
</protection>
|
|
394
875
|
</api>
|
|
395
876
|
</server>
|
|
396
877
|
)
|
|
397
878
|
```
|
|
398
879
|
|
|
399
|
-
|
|
880
|
+
#### searchKey
|
|
400
881
|
|
|
401
|
-
|
|
882
|
+
This prop sets a search query field name used to check protection.
|
|
402
883
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
import { useParams } from '@innet/server'
|
|
884
|
+
By default, it equals `protection`.
|
|
885
|
+
You can use `INNET_PROTECTION_SEARCH_KEY` env to set default `searchKey`.
|
|
406
886
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
887
|
+
*src/app.tsx*
|
|
888
|
+
```typescript jsx
|
|
889
|
+
export default (
|
|
890
|
+
<server>
|
|
891
|
+
<api>
|
|
892
|
+
<protection
|
|
893
|
+
searchKey='secret'
|
|
894
|
+
value='secret'>
|
|
895
|
+
<error
|
|
896
|
+
code='protection'
|
|
897
|
+
status='forbidden'
|
|
898
|
+
/>
|
|
899
|
+
</protection>
|
|
900
|
+
</api>
|
|
901
|
+
</server>
|
|
902
|
+
)
|
|
411
903
|
```
|
|
412
904
|
|
|
413
|
-
You do not need to import types, they generate as namespaces.
|
|
414
|
-
|
|
415
905
|
## API Info
|
|
416
906
|
|
|
417
907
|
The API information elements are here.
|
|
@@ -980,6 +1470,7 @@ This element MUST be placed inside `<endpoint>`.
|
|
|
980
1470
|
It defines request body for the endpoint.
|
|
981
1471
|
`@innet/server` formats and validate the value automatically (real-time).
|
|
982
1472
|
|
|
1473
|
+
*src/app.tsx*
|
|
983
1474
|
```typescript jsx
|
|
984
1475
|
return (
|
|
985
1476
|
<server>
|
|
@@ -1013,10 +1504,130 @@ return (
|
|
|
1013
1504
|
This element MUST be placed inside `<endpoint>`.
|
|
1014
1505
|
It defines response body for the endpoint.
|
|
1015
1506
|
|
|
1507
|
+
*src/app.tsx*
|
|
1508
|
+
```typescript jsx
|
|
1509
|
+
return (
|
|
1510
|
+
<server>
|
|
1511
|
+
<api>
|
|
1512
|
+
<endpoint method='get' path='/settings'>
|
|
1513
|
+
<response>
|
|
1514
|
+
<object />
|
|
1515
|
+
</response>
|
|
1516
|
+
</endpoint>
|
|
1517
|
+
</api>
|
|
1518
|
+
</server>
|
|
1519
|
+
)
|
|
1520
|
+
```
|
|
1521
|
+
|
|
1522
|
+
#### status
|
|
1523
|
+
A status of the `<response>`.
|
|
1524
|
+
Any [HTTP status code](https://swagger.io/specification/#http-codes) can be used as a number of the property.
|
|
1525
|
+
|
|
1526
|
+
By default, `status` equals `'default'`.
|
|
1527
|
+
|
|
1528
|
+
*src/app.tsx*
|
|
1529
|
+
```typescript jsx
|
|
1530
|
+
return (
|
|
1531
|
+
<server>
|
|
1532
|
+
<api>
|
|
1533
|
+
<endpoint method='get' path='/settings'>
|
|
1534
|
+
<response status={200}>
|
|
1535
|
+
<object />
|
|
1536
|
+
</response>
|
|
1537
|
+
</endpoint>
|
|
1538
|
+
</api>
|
|
1539
|
+
</server>
|
|
1540
|
+
)
|
|
1541
|
+
```
|
|
1542
|
+
|
|
1543
|
+
To define a range of response codes, this field MAY contain the uppercase wildcard character `X`.
|
|
1544
|
+
For example, `2XX` represents all response codes between \[200-299].
|
|
1545
|
+
Only the following range definitions are allowed: `1XX`, `2XX`, `3XX`, `4XX` and `5XX`.
|
|
1546
|
+
|
|
1547
|
+
*src/app.tsx*
|
|
1548
|
+
```typescript jsx
|
|
1549
|
+
return (
|
|
1550
|
+
<server>
|
|
1551
|
+
<api>
|
|
1552
|
+
<endpoint method='get' path='/settings'>
|
|
1553
|
+
<response status='2XX'>
|
|
1554
|
+
<object />
|
|
1555
|
+
</response>
|
|
1556
|
+
</endpoint>
|
|
1557
|
+
</api>
|
|
1558
|
+
</server>
|
|
1559
|
+
)
|
|
1560
|
+
```
|
|
1561
|
+
|
|
1562
|
+
Many number statuses have a string id you can use on the property.
|
|
1563
|
+
|
|
1564
|
+
*src/app.tsx*
|
|
1565
|
+
```typescript jsx
|
|
1566
|
+
return (
|
|
1567
|
+
<server>
|
|
1568
|
+
<api>
|
|
1569
|
+
<endpoint method='get' path='/settings'>
|
|
1570
|
+
<response status='notFound'>
|
|
1571
|
+
<object />
|
|
1572
|
+
</response>
|
|
1573
|
+
</endpoint>
|
|
1574
|
+
</api>
|
|
1575
|
+
</server>
|
|
1576
|
+
)
|
|
1577
|
+
```
|
|
1578
|
+
|
|
1579
|
+
You can use many `<response>` elements in an endpoint.
|
|
1580
|
+
|
|
1581
|
+
*src/app.tsx*
|
|
1582
|
+
```typescript jsx
|
|
1583
|
+
return (
|
|
1584
|
+
<server>
|
|
1585
|
+
<api>
|
|
1586
|
+
<endpoint method='get' path='/settings'>
|
|
1587
|
+
<response status='2XX'>
|
|
1588
|
+
<object />
|
|
1589
|
+
</response>
|
|
1590
|
+
<response status='4XX'>
|
|
1591
|
+
<object>
|
|
1592
|
+
<field key='error'>
|
|
1593
|
+
<string />
|
|
1594
|
+
</field>
|
|
1595
|
+
<field optional key='data'>
|
|
1596
|
+
<object />
|
|
1597
|
+
</field>
|
|
1598
|
+
</object>
|
|
1599
|
+
</response>
|
|
1600
|
+
</endpoint>
|
|
1601
|
+
</api>
|
|
1602
|
+
</server>
|
|
1603
|
+
)
|
|
1604
|
+
```
|
|
1605
|
+
|
|
1606
|
+
#### type
|
|
1607
|
+
A media type of the `<response>`.
|
|
1608
|
+
|
|
1609
|
+
By default, `type` equals `'application/json'`.
|
|
1610
|
+
|
|
1611
|
+
*src/app.tsx*
|
|
1612
|
+
```typescript jsx
|
|
1613
|
+
return (
|
|
1614
|
+
<server>
|
|
1615
|
+
<api>
|
|
1616
|
+
<endpoint method='get' path='/hello'>
|
|
1617
|
+
<response type='text/html'>
|
|
1618
|
+
Hello World!
|
|
1619
|
+
</response>
|
|
1620
|
+
</endpoint>
|
|
1621
|
+
</api>
|
|
1622
|
+
</server>
|
|
1623
|
+
)
|
|
1624
|
+
```
|
|
1625
|
+
|
|
1016
1626
|
## Primitive Data
|
|
1017
1627
|
|
|
1018
1628
|
[← back](#index)
|
|
1019
1629
|
|
|
1630
|
+
[\<any>](#any)
|
|
1020
1631
|
[\<null>](#null)
|
|
1021
1632
|
[\<boolean>](#boolean)
|
|
1022
1633
|
[\<string>](#string)
|
|
@@ -1026,6 +1637,142 @@ It defines response body for the endpoint.
|
|
|
1026
1637
|
[\<uuid>](#uuid)
|
|
1027
1638
|
[\<binary>](#binary)
|
|
1028
1639
|
|
|
1640
|
+
### \<any>
|
|
1641
|
+
|
|
1642
|
+
[← back](#primitive-data)
|
|
1643
|
+
|
|
1644
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
1645
|
+
It defines `any` value for a parent element.
|
|
1646
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
1647
|
+
|
|
1648
|
+
*src/app.tsx*
|
|
1649
|
+
```typescript jsx
|
|
1650
|
+
export default (
|
|
1651
|
+
<server>
|
|
1652
|
+
<api>
|
|
1653
|
+
<endpoint method='get' path='/todos'>
|
|
1654
|
+
<param
|
|
1655
|
+
in='query'
|
|
1656
|
+
name='search'>
|
|
1657
|
+
<any />
|
|
1658
|
+
</param>
|
|
1659
|
+
</endpoint>
|
|
1660
|
+
</api>
|
|
1661
|
+
</server>
|
|
1662
|
+
)
|
|
1663
|
+
```
|
|
1664
|
+
|
|
1665
|
+
#### default
|
|
1666
|
+
|
|
1667
|
+
A default value for the `any`.
|
|
1668
|
+
|
|
1669
|
+
*src/app.tsx*
|
|
1670
|
+
```typescript jsx
|
|
1671
|
+
export default (
|
|
1672
|
+
<server>
|
|
1673
|
+
<api>
|
|
1674
|
+
<endpoint method='get' path='/users'>
|
|
1675
|
+
<param
|
|
1676
|
+
in='query'
|
|
1677
|
+
name='search'>
|
|
1678
|
+
<any default={null} />
|
|
1679
|
+
</param>
|
|
1680
|
+
</endpoint>
|
|
1681
|
+
</api>
|
|
1682
|
+
</server>
|
|
1683
|
+
)
|
|
1684
|
+
```
|
|
1685
|
+
|
|
1686
|
+
#### example
|
|
1687
|
+
|
|
1688
|
+
An example value.
|
|
1689
|
+
|
|
1690
|
+
*src/app.tsx*
|
|
1691
|
+
```typescript jsx
|
|
1692
|
+
export default (
|
|
1693
|
+
<server>
|
|
1694
|
+
<api>
|
|
1695
|
+
<endpoint method='get' path='/products'>
|
|
1696
|
+
<param
|
|
1697
|
+
in='query'
|
|
1698
|
+
name='active'>
|
|
1699
|
+
<any example={false} />
|
|
1700
|
+
</param>
|
|
1701
|
+
</endpoint>
|
|
1702
|
+
</api>
|
|
1703
|
+
</server>
|
|
1704
|
+
)
|
|
1705
|
+
```
|
|
1706
|
+
|
|
1707
|
+
#### description
|
|
1708
|
+
|
|
1709
|
+
A description of the `any`.
|
|
1710
|
+
|
|
1711
|
+
*src/app.tsx*
|
|
1712
|
+
```typescript jsx
|
|
1713
|
+
export default (
|
|
1714
|
+
<server>
|
|
1715
|
+
<api>
|
|
1716
|
+
<endpoint method='get' path='/products'>
|
|
1717
|
+
<param
|
|
1718
|
+
in='query'
|
|
1719
|
+
name='active'>
|
|
1720
|
+
<any
|
|
1721
|
+
description='Active products param'
|
|
1722
|
+
/>
|
|
1723
|
+
</param>
|
|
1724
|
+
</endpoint>
|
|
1725
|
+
</api>
|
|
1726
|
+
</server>
|
|
1727
|
+
)
|
|
1728
|
+
```
|
|
1729
|
+
|
|
1730
|
+
### \<null>
|
|
1731
|
+
|
|
1732
|
+
[← back](#primitive-data)
|
|
1733
|
+
|
|
1734
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
1735
|
+
It defines `null` value for a parent element.
|
|
1736
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
1737
|
+
|
|
1738
|
+
*src/app.tsx*
|
|
1739
|
+
```typescript jsx
|
|
1740
|
+
export default (
|
|
1741
|
+
<server>
|
|
1742
|
+
<api>
|
|
1743
|
+
<endpoint method='get' path='/todos'>
|
|
1744
|
+
<param
|
|
1745
|
+
in='query'
|
|
1746
|
+
name='search'>
|
|
1747
|
+
<null />
|
|
1748
|
+
</param>
|
|
1749
|
+
</endpoint>
|
|
1750
|
+
</api>
|
|
1751
|
+
</server>
|
|
1752
|
+
)
|
|
1753
|
+
```
|
|
1754
|
+
|
|
1755
|
+
#### description
|
|
1756
|
+
|
|
1757
|
+
A description of the `null`.
|
|
1758
|
+
|
|
1759
|
+
*src/app.tsx*
|
|
1760
|
+
```typescript jsx
|
|
1761
|
+
export default (
|
|
1762
|
+
<server>
|
|
1763
|
+
<api>
|
|
1764
|
+
<endpoint method='get' path='/products'>
|
|
1765
|
+
<param
|
|
1766
|
+
in='query'
|
|
1767
|
+
name='active'>
|
|
1768
|
+
<null description='FIXME!' />
|
|
1769
|
+
</param>
|
|
1770
|
+
</endpoint>
|
|
1771
|
+
</api>
|
|
1772
|
+
</server>
|
|
1773
|
+
)
|
|
1774
|
+
```
|
|
1775
|
+
|
|
1029
1776
|
### \<boolean>
|
|
1030
1777
|
|
|
1031
1778
|
[← back](#primitive-data)
|
|
@@ -2306,7 +3053,9 @@ export default (
|
|
|
2306
3053
|
<api>
|
|
2307
3054
|
<endpoint method='post' path='/users'>
|
|
2308
3055
|
<body>
|
|
2309
|
-
<object
|
|
3056
|
+
<object>
|
|
3057
|
+
<string />
|
|
3058
|
+
</object>
|
|
2310
3059
|
</body>
|
|
2311
3060
|
</endpoint>
|
|
2312
3061
|
</api>
|
|
@@ -2385,7 +3134,7 @@ The element MUST be placed inside [\<object>](#object).
|
|
|
2385
3134
|
It defines a `field` of an `object` value for a parent element.
|
|
2386
3135
|
`@innet/server` formats and validate the value automatically (real-time).
|
|
2387
3136
|
|
|
2388
|
-
`key` is REQUIRED prop of `<field>`, it defines a field name of the
|
|
3137
|
+
`key` is REQUIRED prop of `<field>`, it defines a field name of the [\<object>](#object).
|
|
2389
3138
|
|
|
2390
3139
|
*src/app.tsx*
|
|
2391
3140
|
```typescript jsx
|
|
@@ -2435,12 +3184,7 @@ Next elements relate to run-time action.
|
|
|
2435
3184
|
This action calls on user request.
|
|
2436
3185
|
|
|
2437
3186
|
[← back](#index)
|
|
2438
|
-
|
|
2439
|
-
Parent
|
|
2440
|
-
[\<fallback>](#fallback)
|
|
2441
|
-
[\<request>](#request)
|
|
2442
|
-
|
|
2443
|
-
Children
|
|
3187
|
+
|
|
2444
3188
|
[\<success>](#success)
|
|
2445
3189
|
[\<error>](#error)
|
|
2446
3190
|
[\<proxy>](#proxy)
|
|
@@ -2452,94 +3196,6 @@ Children
|
|
|
2452
3196
|
|
|
2453
3197
|
---
|
|
2454
3198
|
|
|
2455
|
-
### \<fallback>
|
|
2456
|
-
|
|
2457
|
-
[← back](#run-time)
|
|
2458
|
-
|
|
2459
|
-
By default, `<api>` server returns 404 with empty body.
|
|
2460
|
-
[\<fallback>](#fallback) element defines default server response.
|
|
2461
|
-
This element MUST be placed in `<api>`.
|
|
2462
|
-
You MUST use one [\<fallback>](#fallback) per `<api>`.
|
|
2463
|
-
Can contain elements available inside [\<request>](#request).
|
|
2464
|
-
|
|
2465
|
-
*src/app.tsx*
|
|
2466
|
-
```typescript jsx
|
|
2467
|
-
export default (
|
|
2468
|
-
<server>
|
|
2469
|
-
<api>
|
|
2470
|
-
<fallback>
|
|
2471
|
-
<error
|
|
2472
|
-
code='unknownEndpoint'
|
|
2473
|
-
/>
|
|
2474
|
-
</fallback>
|
|
2475
|
-
</api>
|
|
2476
|
-
</server>
|
|
2477
|
-
)
|
|
2478
|
-
```
|
|
2479
|
-
|
|
2480
|
-
If you open the application on any URL except for `/`, you can see the next response.
|
|
2481
|
-
|
|
2482
|
-
```json
|
|
2483
|
-
{
|
|
2484
|
-
"error": "unknownEndpoint"
|
|
2485
|
-
}
|
|
2486
|
-
```
|
|
2487
|
-
|
|
2488
|
-
The next elements are placed in [\<request>](#request) or [\<fallback>](#fallback)
|
|
2489
|
-
|
|
2490
|
-
### \<request>
|
|
2491
|
-
|
|
2492
|
-
[← back](#run-time)
|
|
2493
|
-
|
|
2494
|
-
This element MUST be placed in `<endpoint>` element.
|
|
2495
|
-
It defines run-time call handler for the endpoint.
|
|
2496
|
-
|
|
2497
|
-
*src/app.tsx*
|
|
2498
|
-
```typescript jsx
|
|
2499
|
-
export default (
|
|
2500
|
-
<server>
|
|
2501
|
-
<api>
|
|
2502
|
-
<endpoint method='get' path='/partners'>
|
|
2503
|
-
<request>
|
|
2504
|
-
<success>
|
|
2505
|
-
{{partners: []}}
|
|
2506
|
-
</success>
|
|
2507
|
-
</request>
|
|
2508
|
-
</endpoint>
|
|
2509
|
-
</api>
|
|
2510
|
-
</server>
|
|
2511
|
-
)
|
|
2512
|
-
```
|
|
2513
|
-
|
|
2514
|
-
You can place a component inside it.
|
|
2515
|
-
The component will run when the endpoint will be triggered.
|
|
2516
|
-
|
|
2517
|
-
*src/app.tsx*
|
|
2518
|
-
```typescript jsx
|
|
2519
|
-
import { GetPartners } from './GetPartners'
|
|
2520
|
-
|
|
2521
|
-
export default (
|
|
2522
|
-
<server>
|
|
2523
|
-
<api>
|
|
2524
|
-
<endpoint method='get' path='/partners'>
|
|
2525
|
-
<request>
|
|
2526
|
-
<GetPartners />
|
|
2527
|
-
</request>
|
|
2528
|
-
</endpoint>
|
|
2529
|
-
</api>
|
|
2530
|
-
</server>
|
|
2531
|
-
)
|
|
2532
|
-
```
|
|
2533
|
-
|
|
2534
|
-
*src/GetPartners.tsx*
|
|
2535
|
-
```typescript jsx
|
|
2536
|
-
export const GetPartners = () => (
|
|
2537
|
-
<success>
|
|
2538
|
-
{{partners: []}}
|
|
2539
|
-
</success>
|
|
2540
|
-
)
|
|
2541
|
-
```
|
|
2542
|
-
|
|
2543
3199
|
### \<success>
|
|
2544
3200
|
|
|
2545
3201
|
[← back](#run-time)
|
|
@@ -2550,11 +3206,9 @@ This is a base element to return a success data.
|
|
|
2550
3206
|
```typescript jsx
|
|
2551
3207
|
export default (
|
|
2552
3208
|
<server>
|
|
2553
|
-
<
|
|
2554
|
-
<
|
|
2555
|
-
|
|
2556
|
-
</fallback>
|
|
2557
|
-
</api>
|
|
3209
|
+
<response>
|
|
3210
|
+
<success />
|
|
3211
|
+
</response>
|
|
2558
3212
|
</server>
|
|
2559
3213
|
)
|
|
2560
3214
|
```
|
|
@@ -2569,13 +3223,11 @@ const data = {...}
|
|
|
2569
3223
|
|
|
2570
3224
|
export default (
|
|
2571
3225
|
<server>
|
|
2572
|
-
<
|
|
2573
|
-
<
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
</fallback>
|
|
2578
|
-
</api>
|
|
3226
|
+
<response>
|
|
3227
|
+
<success>
|
|
3228
|
+
{data}
|
|
3229
|
+
</success>
|
|
3230
|
+
</response>
|
|
2579
3231
|
</server>
|
|
2580
3232
|
)
|
|
2581
3233
|
```
|
|
@@ -2592,13 +3244,11 @@ const data = {...}
|
|
|
2592
3244
|
|
|
2593
3245
|
export default (
|
|
2594
3246
|
<server>
|
|
2595
|
-
<
|
|
2596
|
-
<
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
</fallback>
|
|
2601
|
-
</api>
|
|
3247
|
+
<response>
|
|
3248
|
+
<success status='created'>
|
|
3249
|
+
{data}
|
|
3250
|
+
</success>
|
|
3251
|
+
</response>
|
|
2602
3252
|
</server>
|
|
2603
3253
|
)
|
|
2604
3254
|
```
|
|
@@ -2613,13 +3263,29 @@ const data = {...}
|
|
|
2613
3263
|
|
|
2614
3264
|
export default (
|
|
2615
3265
|
<server>
|
|
2616
|
-
<
|
|
2617
|
-
<
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
3266
|
+
<response>
|
|
3267
|
+
<success status={201}>
|
|
3268
|
+
{data}
|
|
3269
|
+
</success>
|
|
3270
|
+
</response>
|
|
3271
|
+
</server>
|
|
3272
|
+
)
|
|
3273
|
+
```
|
|
3274
|
+
|
|
3275
|
+
#### contentType
|
|
3276
|
+
|
|
3277
|
+
This props sets response content type.
|
|
3278
|
+
By default, it checks children element to define the prop.
|
|
3279
|
+
|
|
3280
|
+
*src/app.tsx*
|
|
3281
|
+
```typescript jsx
|
|
3282
|
+
export default (
|
|
3283
|
+
<server>
|
|
3284
|
+
<response>
|
|
3285
|
+
<success contentType='text/html'>
|
|
3286
|
+
Hello World!
|
|
3287
|
+
</success>
|
|
3288
|
+
</response>
|
|
2623
3289
|
</server>
|
|
2624
3290
|
)
|
|
2625
3291
|
```
|
|
@@ -2629,17 +3295,15 @@ export default (
|
|
|
2629
3295
|
[← back](#run-time)
|
|
2630
3296
|
|
|
2631
3297
|
Returns an error.
|
|
2632
|
-
This element MUST be placed in [\<request>](#request) or [\<
|
|
3298
|
+
This element MUST be placed in [\<request>](#request) or [\<response>](#response).
|
|
2633
3299
|
|
|
2634
3300
|
*src/app.tsx*
|
|
2635
3301
|
```typescript jsx
|
|
2636
3302
|
export default (
|
|
2637
3303
|
<server>
|
|
2638
|
-
<
|
|
2639
|
-
<
|
|
2640
|
-
|
|
2641
|
-
</fallback>
|
|
2642
|
-
</api>
|
|
3304
|
+
<response>
|
|
3305
|
+
<error />
|
|
3306
|
+
</response>
|
|
2643
3307
|
</server>
|
|
2644
3308
|
)
|
|
2645
3309
|
```
|
|
@@ -2652,13 +3316,11 @@ const data = {...}
|
|
|
2652
3316
|
|
|
2653
3317
|
export default (
|
|
2654
3318
|
<server>
|
|
2655
|
-
<
|
|
2656
|
-
<
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
</fallback>
|
|
2661
|
-
</api>
|
|
3319
|
+
<response>
|
|
3320
|
+
<error>
|
|
3321
|
+
{data}
|
|
3322
|
+
</error>
|
|
3323
|
+
</response>
|
|
2662
3324
|
</server>
|
|
2663
3325
|
)
|
|
2664
3326
|
```
|
|
@@ -2674,13 +3336,11 @@ const data = {
|
|
|
2674
3336
|
|
|
2675
3337
|
export default (
|
|
2676
3338
|
<server>
|
|
2677
|
-
<
|
|
2678
|
-
<
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
</fallback>
|
|
2683
|
-
</api>
|
|
3339
|
+
<response>
|
|
3340
|
+
<error status='notFound'>
|
|
3341
|
+
{data}
|
|
3342
|
+
</error>
|
|
3343
|
+
</response>
|
|
2684
3344
|
</server>
|
|
2685
3345
|
)
|
|
2686
3346
|
```
|
|
@@ -2695,13 +3355,11 @@ const data = {
|
|
|
2695
3355
|
|
|
2696
3356
|
export default (
|
|
2697
3357
|
<server>
|
|
2698
|
-
<
|
|
2699
|
-
<
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
</fallback>
|
|
2704
|
-
</api>
|
|
3358
|
+
<response>
|
|
3359
|
+
<error status={404}>
|
|
3360
|
+
{data}
|
|
3361
|
+
</error>
|
|
3362
|
+
</response>
|
|
2705
3363
|
</server>
|
|
2706
3364
|
)
|
|
2707
3365
|
```
|
|
@@ -2729,15 +3387,13 @@ const data = {
|
|
|
2729
3387
|
|
|
2730
3388
|
export default (
|
|
2731
3389
|
<server>
|
|
2732
|
-
<
|
|
2733
|
-
<
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
</fallback>
|
|
2740
|
-
</api>
|
|
3390
|
+
<response>
|
|
3391
|
+
<error
|
|
3392
|
+
code='noUser'
|
|
3393
|
+
status='notFound'>
|
|
3394
|
+
{data}
|
|
3395
|
+
</error>
|
|
3396
|
+
</response>
|
|
2741
3397
|
</server>
|
|
2742
3398
|
)
|
|
2743
3399
|
```
|
|
@@ -2765,7 +3421,7 @@ There are some default errors:
|
|
|
2765
3421
|
|
|
2766
3422
|
[← back](#run-time)
|
|
2767
3423
|
|
|
2768
|
-
MUST be placed in [\<request>](#request) or [\<
|
|
3424
|
+
MUST be placed in [\<request>](#request) or [\<response>](#response).
|
|
2769
3425
|
|
|
2770
3426
|
You can easy proxy endpoints to another server/service.
|
|
2771
3427
|
|
|
@@ -2781,10 +3437,10 @@ export default (
|
|
|
2781
3437
|
<proxy to='https://...' />
|
|
2782
3438
|
</request>
|
|
2783
3439
|
</endpoint>
|
|
2784
|
-
<fallback>
|
|
2785
|
-
<proxy to='https://...' />
|
|
2786
|
-
</fallback>
|
|
2787
3440
|
</api>
|
|
3441
|
+
<response>
|
|
3442
|
+
<proxy to='https://...' />
|
|
3443
|
+
</response>
|
|
2788
3444
|
</server>
|
|
2789
3445
|
)
|
|
2790
3446
|
```
|
|
@@ -2793,7 +3449,7 @@ export default (
|
|
|
2793
3449
|
|
|
2794
3450
|
[← back](#run-time)
|
|
2795
3451
|
|
|
2796
|
-
MUST be placed in [\<request>](#request) or [\<
|
|
3452
|
+
MUST be placed in [\<request>](#request) or [\<response>](#response).
|
|
2797
3453
|
|
|
2798
3454
|
You can redirect users to another resource. It adds `Cache-Control` header by default.
|
|
2799
3455
|
|
|
@@ -2809,10 +3465,10 @@ export default (
|
|
|
2809
3465
|
<redirect to='https://...' />
|
|
2810
3466
|
</request>
|
|
2811
3467
|
</endpoint>
|
|
2812
|
-
<fallback>
|
|
2813
|
-
<redirect to='https://...' />
|
|
2814
|
-
</fallback>
|
|
2815
3468
|
</api>
|
|
3469
|
+
<response>
|
|
3470
|
+
<redirect to='https://...' />
|
|
3471
|
+
</response>
|
|
2816
3472
|
</server>
|
|
2817
3473
|
)
|
|
2818
3474
|
```
|
|
@@ -2837,13 +3493,13 @@ export default (
|
|
|
2837
3493
|
/>
|
|
2838
3494
|
</request>
|
|
2839
3495
|
</endpoint>
|
|
2840
|
-
<fallback>
|
|
2841
|
-
<redirect
|
|
2842
|
-
status={303}
|
|
2843
|
-
to='https://...'
|
|
2844
|
-
/>
|
|
2845
|
-
</fallback>
|
|
2846
3496
|
</api>
|
|
3497
|
+
<response>
|
|
3498
|
+
<redirect
|
|
3499
|
+
status={303}
|
|
3500
|
+
to='https://...'
|
|
3501
|
+
/>
|
|
3502
|
+
</response>
|
|
2847
3503
|
</server>
|
|
2848
3504
|
)
|
|
2849
3505
|
```
|
|
@@ -2852,7 +3508,7 @@ export default (
|
|
|
2852
3508
|
|
|
2853
3509
|
[← back](#run-time)
|
|
2854
3510
|
|
|
2855
|
-
MUST be placed in [\<request>](#request) or [\<
|
|
3511
|
+
MUST be placed in [\<request>](#request) or [\<response>](#response).
|
|
2856
3512
|
|
|
2857
3513
|
`<cms>` helps to return files from a folder by path. It checks files run-time on the server.
|
|
2858
3514
|
|
|
@@ -2860,18 +3516,16 @@ MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
|
2860
3516
|
```typescript jsx
|
|
2861
3517
|
export default (
|
|
2862
3518
|
<server>
|
|
2863
|
-
<
|
|
2864
|
-
<
|
|
2865
|
-
|
|
2866
|
-
</fallback>
|
|
2867
|
-
</api>
|
|
3519
|
+
<response>
|
|
3520
|
+
<cms />
|
|
3521
|
+
</response>
|
|
2868
3522
|
</server>
|
|
2869
3523
|
)
|
|
2870
3524
|
```
|
|
2871
3525
|
|
|
2872
3526
|
#### dir
|
|
2873
3527
|
|
|
2874
|
-
By default, it
|
|
3528
|
+
By default, it equals `INNET_CMS_DIR` node env variable or the project folder.
|
|
2875
3529
|
If you try the previous example on [http://localhost/package.json](http://localhost/package.json)
|
|
2876
3530
|
you get the project `package.json` file.
|
|
2877
3531
|
|
|
@@ -2881,11 +3535,9 @@ You can change root folder by `dir` property.
|
|
|
2881
3535
|
```typescript jsx
|
|
2882
3536
|
export default (
|
|
2883
3537
|
<server>
|
|
2884
|
-
<
|
|
2885
|
-
<
|
|
2886
|
-
|
|
2887
|
-
</fallback>
|
|
2888
|
-
</api>
|
|
3538
|
+
<response>
|
|
3539
|
+
<cms dir='src' />
|
|
3540
|
+
</response>
|
|
2889
3541
|
</server>
|
|
2890
3542
|
)
|
|
2891
3543
|
```
|
|
@@ -2896,15 +3548,16 @@ you get the index file in `src` folder.
|
|
|
2896
3548
|
#### prefix
|
|
2897
3549
|
|
|
2898
3550
|
`<cms>` matches full `path`, you should take it into account if you add `prefix` on `<api>`.
|
|
3551
|
+
By default, it equals `INNET_CMS_PREFIX` node env variable or `/`.
|
|
2899
3552
|
|
|
2900
3553
|
*src/app.tsx*
|
|
2901
3554
|
```typescript jsx
|
|
2902
3555
|
export default (
|
|
2903
3556
|
<server>
|
|
2904
3557
|
<api prefix='/src'>
|
|
2905
|
-
<
|
|
3558
|
+
<response>
|
|
2906
3559
|
<cms />
|
|
2907
|
-
</
|
|
3560
|
+
</response>
|
|
2908
3561
|
</api>
|
|
2909
3562
|
</server>
|
|
2910
3563
|
)
|
|
@@ -2920,9 +3573,9 @@ You can reduce the path for matching by prefix property of `<cms>`.
|
|
|
2920
3573
|
export default (
|
|
2921
3574
|
<server>
|
|
2922
3575
|
<api prefix='/api'>
|
|
2923
|
-
<
|
|
3576
|
+
<response>
|
|
2924
3577
|
<cms prefix='/api' />
|
|
2925
|
-
</
|
|
3578
|
+
</response>
|
|
2926
3579
|
</api>
|
|
2927
3580
|
</server>
|
|
2928
3581
|
)
|
|
@@ -2938,13 +3591,11 @@ You can handle if a file was not found by children elements of `<cms>`.
|
|
|
2938
3591
|
```typescript jsx
|
|
2939
3592
|
export default (
|
|
2940
3593
|
<server>
|
|
2941
|
-
<
|
|
2942
|
-
<
|
|
2943
|
-
<
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
</fallback>
|
|
2947
|
-
</api>
|
|
3594
|
+
<response>
|
|
3595
|
+
<cms>
|
|
3596
|
+
<error status={404} />
|
|
3597
|
+
</cms>
|
|
3598
|
+
</response>
|
|
2948
3599
|
</server>
|
|
2949
3600
|
)
|
|
2950
3601
|
```
|
|
@@ -2953,7 +3604,7 @@ export default (
|
|
|
2953
3604
|
|
|
2954
3605
|
[← back](#run-time)
|
|
2955
3606
|
|
|
2956
|
-
It returns a file. MUST be placed in [\<request>](#request) or [\<
|
|
3607
|
+
It returns a file. MUST be placed in [\<request>](#request) or [\<response>](#response).
|
|
2957
3608
|
|
|
2958
3609
|
It adds `Content-Length` and `Content-Type` automatically.
|
|
2959
3610
|
|
|
@@ -2963,13 +3614,9 @@ It has a REQUIRED property of `path`.
|
|
|
2963
3614
|
```typescript jsx
|
|
2964
3615
|
export default (
|
|
2965
3616
|
<server>
|
|
2966
|
-
<
|
|
2967
|
-
<
|
|
2968
|
-
|
|
2969
|
-
path='package.json'
|
|
2970
|
-
/>
|
|
2971
|
-
</fallback>
|
|
2972
|
-
</api>
|
|
3617
|
+
<response>
|
|
3618
|
+
<file path='package.json' />
|
|
3619
|
+
</response>
|
|
2973
3620
|
</server>
|
|
2974
3621
|
)
|
|
2975
3622
|
```
|
|
@@ -2984,20 +3631,18 @@ You can handle if a file was not found by children elements of `<file>`.
|
|
|
2984
3631
|
```typescript jsx
|
|
2985
3632
|
export default (
|
|
2986
3633
|
<server>
|
|
2987
|
-
<
|
|
2988
|
-
<
|
|
2989
|
-
<
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
</fallback>
|
|
2993
|
-
</api>
|
|
3634
|
+
<response>
|
|
3635
|
+
<file path='file_is_not_exist.txt'>
|
|
3636
|
+
<error status={404} />
|
|
3637
|
+
</file>
|
|
3638
|
+
</response>
|
|
2994
3639
|
</server>
|
|
2995
3640
|
)
|
|
2996
3641
|
```
|
|
2997
3642
|
|
|
2998
3643
|
### \<header>
|
|
2999
3644
|
|
|
3000
|
-
MUST be placed in [\<request>](#request) or [\<
|
|
3645
|
+
MUST be placed in [\<request>](#request) or [\<response>](#response).
|
|
3001
3646
|
|
|
3002
3647
|
[← back](#run-time)
|
|
3003
3648
|
|
|
@@ -3007,22 +3652,20 @@ You can add an HTTP header into response by `<header>` element.
|
|
|
3007
3652
|
```typescript jsx
|
|
3008
3653
|
export default (
|
|
3009
3654
|
<server>
|
|
3010
|
-
<
|
|
3011
|
-
<
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
</fallback>
|
|
3018
|
-
</api>
|
|
3655
|
+
<response>
|
|
3656
|
+
<header
|
|
3657
|
+
key='Cache-Control'
|
|
3658
|
+
value='no-cache, no-store, must-revalidate'
|
|
3659
|
+
/>
|
|
3660
|
+
<success />
|
|
3661
|
+
</response>
|
|
3019
3662
|
</server>
|
|
3020
3663
|
)
|
|
3021
3664
|
```
|
|
3022
3665
|
|
|
3023
3666
|
### \<cookie>
|
|
3024
3667
|
|
|
3025
|
-
MUST be placed in [\<request>](#request) or [\<
|
|
3668
|
+
MUST be placed in [\<request>](#request) or [\<response>](#response).
|
|
3026
3669
|
|
|
3027
3670
|
[← back](#run-time)
|
|
3028
3671
|
|
|
@@ -3032,18 +3675,16 @@ You can add/remove a cookie into response by `<cookie>` element.
|
|
|
3032
3675
|
```typescript jsx
|
|
3033
3676
|
export default (
|
|
3034
3677
|
<server>
|
|
3035
|
-
<
|
|
3036
|
-
<
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
</fallback>
|
|
3046
|
-
</api>
|
|
3678
|
+
<response>
|
|
3679
|
+
<cookie
|
|
3680
|
+
key='token'
|
|
3681
|
+
value='...'
|
|
3682
|
+
/>
|
|
3683
|
+
<cookie
|
|
3684
|
+
key='removedCookie'
|
|
3685
|
+
/>
|
|
3686
|
+
<success />
|
|
3687
|
+
</response>
|
|
3047
3688
|
</server>
|
|
3048
3689
|
)
|
|
3049
3690
|
```
|
|
@@ -3057,16 +3698,14 @@ By default, no domain is set, and most clients will consider the cookie to apply
|
|
|
3057
3698
|
```typescript jsx
|
|
3058
3699
|
export default (
|
|
3059
3700
|
<server>
|
|
3060
|
-
<
|
|
3061
|
-
<
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
</fallback>
|
|
3069
|
-
</api>
|
|
3701
|
+
<response>
|
|
3702
|
+
<cookie
|
|
3703
|
+
domain='.example.com'
|
|
3704
|
+
key='token'
|
|
3705
|
+
value='...'
|
|
3706
|
+
/>
|
|
3707
|
+
<success />
|
|
3708
|
+
</response>
|
|
3070
3709
|
</server>
|
|
3071
3710
|
)
|
|
3072
3711
|
```
|
|
@@ -3085,16 +3724,14 @@ Note the [cookie storage model specification](https://datatracker.ietf.org/doc/h
|
|
|
3085
3724
|
```typescript jsx
|
|
3086
3725
|
export default (
|
|
3087
3726
|
<server>
|
|
3088
|
-
<
|
|
3089
|
-
<
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
</fallback>
|
|
3097
|
-
</api>
|
|
3727
|
+
<response>
|
|
3728
|
+
<cookie
|
|
3729
|
+
expires={new Date('2050-01-01')}
|
|
3730
|
+
key='token'
|
|
3731
|
+
value='...'
|
|
3732
|
+
/>
|
|
3733
|
+
<success />
|
|
3734
|
+
</response>
|
|
3098
3735
|
</server>
|
|
3099
3736
|
)
|
|
3100
3737
|
```
|
|
@@ -3108,16 +3745,14 @@ Note be careful when setting this to true, as compliant clients will not allow c
|
|
|
3108
3745
|
```typescript jsx
|
|
3109
3746
|
export default (
|
|
3110
3747
|
<server>
|
|
3111
|
-
<
|
|
3112
|
-
<
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
</fallback>
|
|
3120
|
-
</api>
|
|
3748
|
+
<response>
|
|
3749
|
+
<cookie
|
|
3750
|
+
httpOnly
|
|
3751
|
+
key='token'
|
|
3752
|
+
value='...'
|
|
3753
|
+
/>
|
|
3754
|
+
<success />
|
|
3755
|
+
</response>
|
|
3121
3756
|
</server>
|
|
3122
3757
|
)
|
|
3123
3758
|
```
|
|
@@ -3131,17 +3766,15 @@ Note the [cookie storage model specification](https://datatracker.ietf.org/doc/h
|
|
|
3131
3766
|
```typescript jsx
|
|
3132
3767
|
export default (
|
|
3133
3768
|
<server>
|
|
3134
|
-
<
|
|
3135
|
-
<
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
</fallback>
|
|
3144
|
-
</api>
|
|
3769
|
+
<response>
|
|
3770
|
+
<cookie
|
|
3771
|
+
httpOnly
|
|
3772
|
+
maxAge={9999}
|
|
3773
|
+
key='token'
|
|
3774
|
+
value='...'
|
|
3775
|
+
/>
|
|
3776
|
+
<success />
|
|
3777
|
+
</response>
|
|
3145
3778
|
</server>
|
|
3146
3779
|
)
|
|
3147
3780
|
```
|
|
@@ -3155,18 +3788,16 @@ By default, the path is considered the “default path”.
|
|
|
3155
3788
|
```typescript jsx
|
|
3156
3789
|
export default (
|
|
3157
3790
|
<server>
|
|
3158
|
-
<
|
|
3159
|
-
<
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
</fallback>
|
|
3169
|
-
</api>
|
|
3791
|
+
<response>
|
|
3792
|
+
<cookie
|
|
3793
|
+
httpOnly
|
|
3794
|
+
maxAge={9999}
|
|
3795
|
+
path='/src'
|
|
3796
|
+
key='token'
|
|
3797
|
+
value='...'
|
|
3798
|
+
/>
|
|
3799
|
+
<success />
|
|
3800
|
+
</response>
|
|
3170
3801
|
</server>
|
|
3171
3802
|
)
|
|
3172
3803
|
```
|
|
@@ -3185,18 +3816,16 @@ note This is an attribute that has not yet been fully standardized, and may chan
|
|
|
3185
3816
|
```typescript jsx
|
|
3186
3817
|
export default (
|
|
3187
3818
|
<server>
|
|
3188
|
-
<
|
|
3189
|
-
<
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
</fallback>
|
|
3199
|
-
</api>
|
|
3819
|
+
<response>
|
|
3820
|
+
<cookie
|
|
3821
|
+
httpOnly
|
|
3822
|
+
priority='high'
|
|
3823
|
+
path='/src'
|
|
3824
|
+
key='token'
|
|
3825
|
+
value='...'
|
|
3826
|
+
/>
|
|
3827
|
+
<success />
|
|
3828
|
+
</response>
|
|
3200
3829
|
</server>
|
|
3201
3830
|
)
|
|
3202
3831
|
```
|
|
@@ -3218,19 +3847,17 @@ This also means many clients may ignore this attribute until they understand it.
|
|
|
3218
3847
|
```typescript jsx
|
|
3219
3848
|
export default (
|
|
3220
3849
|
<server>
|
|
3221
|
-
<
|
|
3222
|
-
<
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
</fallback>
|
|
3233
|
-
</api>
|
|
3850
|
+
<response>
|
|
3851
|
+
<cookie
|
|
3852
|
+
httpOnly
|
|
3853
|
+
sameSite
|
|
3854
|
+
priority='high'
|
|
3855
|
+
path='/src'
|
|
3856
|
+
key='token'
|
|
3857
|
+
value='...'
|
|
3858
|
+
/>
|
|
3859
|
+
<success />
|
|
3860
|
+
</response>
|
|
3234
3861
|
</server>
|
|
3235
3862
|
)
|
|
3236
3863
|
```
|
|
@@ -3247,17 +3874,15 @@ Note be careful when setting this to true, as compliant clients will not send th
|
|
|
3247
3874
|
```typescript jsx
|
|
3248
3875
|
export default (
|
|
3249
3876
|
<server>
|
|
3250
|
-
<
|
|
3251
|
-
<
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
</fallback>
|
|
3260
|
-
</api>
|
|
3877
|
+
<response>
|
|
3878
|
+
<cookie
|
|
3879
|
+
httpOnly
|
|
3880
|
+
secure
|
|
3881
|
+
key='token'
|
|
3882
|
+
value='...'
|
|
3883
|
+
/>
|
|
3884
|
+
<success />
|
|
3885
|
+
</response>
|
|
3261
3886
|
</server>
|
|
3262
3887
|
)
|
|
3263
3888
|
```
|
|
@@ -3290,14 +3915,12 @@ import { SetToken } from './SetToken'
|
|
|
3290
3915
|
|
|
3291
3916
|
export default (
|
|
3292
3917
|
<server>
|
|
3293
|
-
<
|
|
3294
|
-
<
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
</fallback>
|
|
3300
|
-
</api>
|
|
3918
|
+
<response>
|
|
3919
|
+
<SetToken
|
|
3920
|
+
value='...'
|
|
3921
|
+
/>
|
|
3922
|
+
<success />
|
|
3923
|
+
</response>
|
|
3301
3924
|
</server>
|
|
3302
3925
|
)
|
|
3303
3926
|
```
|
|
@@ -3310,7 +3933,7 @@ Hook functions give you all features to control parent element functionality.
|
|
|
3310
3933
|
|
|
3311
3934
|
[← back](#index)
|
|
3312
3935
|
|
|
3313
|
-
|
|
3936
|
+
Real-time
|
|
3314
3937
|
[useRequest](#userequest)
|
|
3315
3938
|
[useResponse](#useresponse)
|
|
3316
3939
|
[useHeaders](#useheaders)
|
|
@@ -3319,35 +3942,22 @@ Hook functions give you all features to control parent element functionality.
|
|
|
3319
3942
|
[useParams](#useparams)
|
|
3320
3943
|
[useSearch](#usesearch)
|
|
3321
3944
|
[useBody](#usebody)
|
|
3945
|
+
[useClientIp](#useclientip)
|
|
3322
3946
|
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
### useServer
|
|
3326
|
-
|
|
3327
|
-
[← back](#hooks)
|
|
3328
|
-
|
|
3329
|
-
This hook MUST be used in a component placed in `<server>`.
|
|
3330
|
-
This hook returns current http(s) server instance.
|
|
3331
|
-
|
|
3332
|
-
*src/Component.tsx*
|
|
3333
|
-
|
|
3334
|
-
```typescript jsx
|
|
3335
|
-
import { useServer } from '@innet/sever'
|
|
3336
|
-
|
|
3337
|
-
export function Component () {
|
|
3338
|
-
const server = useServer()
|
|
3947
|
+
Server start
|
|
3948
|
+
[useServerPlugin](#useserverplugin)
|
|
3339
3949
|
|
|
3340
|
-
|
|
3950
|
+
Both
|
|
3951
|
+
[useServer](#useserver)
|
|
3952
|
+
[useComponentName](#usecomponentname)
|
|
3341
3953
|
|
|
3342
|
-
|
|
3343
|
-
}
|
|
3344
|
-
```
|
|
3954
|
+
---
|
|
3345
3955
|
|
|
3346
3956
|
### useRequest
|
|
3347
3957
|
|
|
3348
3958
|
[← back](#hooks)
|
|
3349
3959
|
|
|
3350
|
-
This hook MUST be used in a component placed in [\<request>](#request) or [\<
|
|
3960
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<response>](#response).
|
|
3351
3961
|
This hook returns current request instance.
|
|
3352
3962
|
|
|
3353
3963
|
*src/Component.tsx*
|
|
@@ -3368,7 +3978,7 @@ export function Component () {
|
|
|
3368
3978
|
|
|
3369
3979
|
[← back](#hooks)
|
|
3370
3980
|
|
|
3371
|
-
This hook MUST be used in a component placed in [\<request>](#request) or [\<
|
|
3981
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<response>](#response).
|
|
3372
3982
|
This hook returns current response instance.
|
|
3373
3983
|
|
|
3374
3984
|
*src/Component.tsx*
|
|
@@ -3389,7 +3999,7 @@ export function Component () {
|
|
|
3389
3999
|
|
|
3390
4000
|
[← back](#hooks)
|
|
3391
4001
|
|
|
3392
|
-
This hook MUST be used in a component placed in [\<request>](#request) or [\<
|
|
4002
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<response>](#response).
|
|
3393
4003
|
This hook returns current request headers object.
|
|
3394
4004
|
|
|
3395
4005
|
*src/Component.tsx*
|
|
@@ -3408,7 +4018,7 @@ export function Component () {
|
|
|
3408
4018
|
|
|
3409
4019
|
[← back](#hooks)
|
|
3410
4020
|
|
|
3411
|
-
This hook MUST be used in a component placed in [\<request>](#request) or [\<
|
|
4021
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<response>](#response).
|
|
3412
4022
|
This hook returns current request cookies object.
|
|
3413
4023
|
|
|
3414
4024
|
*src/Component.tsx*
|
|
@@ -3427,7 +4037,7 @@ export function Component () {
|
|
|
3427
4037
|
|
|
3428
4038
|
[← back](#hooks)
|
|
3429
4039
|
|
|
3430
|
-
This hook MUST be used in a component placed in [\<request>](#request) or [\<
|
|
4040
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<response>](#response).
|
|
3431
4041
|
This hook returns current request URL path as a `string`.
|
|
3432
4042
|
|
|
3433
4043
|
*src/Component.tsx*
|
|
@@ -3446,7 +4056,7 @@ export function Component () {
|
|
|
3446
4056
|
|
|
3447
4057
|
[← back](#hooks)
|
|
3448
4058
|
|
|
3449
|
-
This hook MUST be used in a component placed in [\<request>](#request) or [\<
|
|
4059
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<response>](#response).
|
|
3450
4060
|
This hook returns an object of URL params you set by [\<param>](#param).
|
|
3451
4061
|
|
|
3452
4062
|
*src/Component.tsx*
|
|
@@ -3464,7 +4074,7 @@ export function Component () {
|
|
|
3464
4074
|
|
|
3465
4075
|
[← back](#hooks)
|
|
3466
4076
|
|
|
3467
|
-
This hook MUST be used in a component placed in [\<request>](#request) or [\<
|
|
4077
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<response>](#response).
|
|
3468
4078
|
This hook returns an object of URL query params.
|
|
3469
4079
|
|
|
3470
4080
|
*src/Component.tsx*
|
|
@@ -3482,7 +4092,7 @@ export function Component () {
|
|
|
3482
4092
|
|
|
3483
4093
|
[← back](#hooks)
|
|
3484
4094
|
|
|
3485
|
-
This hook MUST be used in a component placed in [\<request>](#request) or [\<
|
|
4095
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<response>](#response).
|
|
3486
4096
|
This hook returns current request body.
|
|
3487
4097
|
|
|
3488
4098
|
*src/Component.tsx*
|
|
@@ -3496,6 +4106,106 @@ export function Component () {
|
|
|
3496
4106
|
}
|
|
3497
4107
|
```
|
|
3498
4108
|
|
|
4109
|
+
### useClientIp
|
|
4110
|
+
|
|
4111
|
+
[← back](#hooks)
|
|
4112
|
+
|
|
4113
|
+
This hook returns request user IP.
|
|
4114
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<response>](#response).
|
|
4115
|
+
|
|
4116
|
+
*src/Component.tsx*
|
|
4117
|
+
```typescript jsx
|
|
4118
|
+
import { useClientIp } from '@innet/sever'
|
|
4119
|
+
|
|
4120
|
+
export function Component () {
|
|
4121
|
+
const ip = useClientIp()
|
|
4122
|
+
|
|
4123
|
+
return <success>{{ ip }}</success>
|
|
4124
|
+
}
|
|
4125
|
+
```
|
|
4126
|
+
|
|
4127
|
+
### useServerPlugin
|
|
4128
|
+
|
|
4129
|
+
[← back](#hooks)
|
|
4130
|
+
|
|
4131
|
+
This hook adds a request plugin function.
|
|
4132
|
+
The function runs before check endpoints.
|
|
4133
|
+
If the function returns `true` the request handling stops, and you get full control over the request.
|
|
4134
|
+
|
|
4135
|
+
This hook MUST be used in a component placed in [\<server>](#server).
|
|
4136
|
+
|
|
4137
|
+
*src/SecretEndpoint.tsx*
|
|
4138
|
+
```typescript jsx
|
|
4139
|
+
import { useRequestPlugin, useAction } from '@innet/sever'
|
|
4140
|
+
|
|
4141
|
+
export function SecretEndpoint () {
|
|
4142
|
+
useServerPlugin(() => {
|
|
4143
|
+
const action = useAction()
|
|
4144
|
+
|
|
4145
|
+
if (action.path.startsWith('/secret-endpoint')) {
|
|
4146
|
+
return <success>A secret message</success>
|
|
4147
|
+
}
|
|
4148
|
+
})
|
|
4149
|
+
}
|
|
4150
|
+
```
|
|
4151
|
+
|
|
4152
|
+
Then use the plugin in [\<server>](#server) or [\<api>](#api).
|
|
4153
|
+
|
|
4154
|
+
*src/app.tsx*
|
|
4155
|
+
```typescript jsx
|
|
4156
|
+
import { SecretEndpoint } from './SecretEndpoint'
|
|
4157
|
+
|
|
4158
|
+
export default (
|
|
4159
|
+
<server>
|
|
4160
|
+
<SecretEndpoint />
|
|
4161
|
+
<response>
|
|
4162
|
+
<error />
|
|
4163
|
+
</response>
|
|
4164
|
+
</server>
|
|
4165
|
+
)
|
|
4166
|
+
```
|
|
4167
|
+
|
|
4168
|
+
Any endpoint returns an error except for `/secret-endpoint`.
|
|
4169
|
+
Elements order does not matter.
|
|
4170
|
+
|
|
4171
|
+
### useServer
|
|
4172
|
+
|
|
4173
|
+
[← back](#hooks)
|
|
4174
|
+
|
|
4175
|
+
This hook MUST be used in a component placed in [\<server>](#server).
|
|
4176
|
+
This hook returns current http(s) server instance.
|
|
4177
|
+
|
|
4178
|
+
*src/Component.tsx*
|
|
4179
|
+
```typescript jsx
|
|
4180
|
+
import { useServer } from '@innet/sever'
|
|
4181
|
+
|
|
4182
|
+
export function Component () {
|
|
4183
|
+
const server = useServer()
|
|
4184
|
+
|
|
4185
|
+
console.log(server)
|
|
4186
|
+
|
|
4187
|
+
return <success />
|
|
4188
|
+
}
|
|
4189
|
+
```
|
|
4190
|
+
|
|
4191
|
+
### useComponentName
|
|
4192
|
+
|
|
4193
|
+
[← back](#hooks)
|
|
4194
|
+
|
|
4195
|
+
This hook returns name of current component.
|
|
4196
|
+
|
|
4197
|
+
*src/Component.tsx*
|
|
4198
|
+
```typescript jsx
|
|
4199
|
+
import { useComponentName } from '@innet/sever'
|
|
4200
|
+
|
|
4201
|
+
export function Component () {
|
|
4202
|
+
// returns this ^-------^
|
|
4203
|
+
const name = useComponentName()
|
|
4204
|
+
|
|
4205
|
+
return <success>{{ name }}</success>
|
|
4206
|
+
}
|
|
4207
|
+
```
|
|
4208
|
+
|
|
3499
4209
|
## Issues
|
|
3500
4210
|
If you find a bug or have a suggestion, please file an issue on [GitHub](https://github.com/d8corp/innet-server/issues).
|
|
3501
4211
|
|