@innet/server 2.0.0-alpha.3 → 2.0.0-alpha.30
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 +1375 -541
- package/handler/handler.d.ts +19 -13
- package/handler/handler.es6.js +17 -11
- package/handler/handler.js +17 -11
- package/hooks/index.d.ts +6 -0
- package/hooks/index.es6.js +6 -0
- package/hooks/index.js +6 -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.d.ts +1 -1
- package/hooks/useEndpoint/useEndpoint.es6.js +3 -1
- package/hooks/useEndpoint/useEndpoint.js +3 -1
- package/hooks/useIsServerHttps/index.d.ts +1 -0
- package/hooks/useIsServerHttps/index.es6.js +1 -0
- package/hooks/useIsServerHttps/index.js +10 -0
- package/hooks/useIsServerHttps/useIsServerHttps.d.ts +3 -0
- package/hooks/useIsServerHttps/useIsServerHttps.es6.js +14 -0
- package/hooks/useIsServerHttps/useIsServerHttps.js +19 -0
- 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 +5 -6
- package/hooks/useSchemaType/useSchemaType.js +5 -6
- package/hooks/useServer/useServer.d.ts +2 -1
- 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/hooks/useServerPort/index.d.ts +1 -0
- package/hooks/useServerPort/index.es6.js +1 -0
- package/hooks/useServerPort/index.js +10 -0
- package/hooks/useServerPort/useServerPort.d.ts +3 -0
- package/hooks/useServerPort/useServerPort.es6.js +14 -0
- package/hooks/useServerPort/useServerPort.js +19 -0
- package/index.es6.js +17 -8
- package/index.js +34 -12
- package/package.json +2 -2
- package/plugins/main/api/api.d.ts +10 -8
- package/plugins/main/api/api.es6.js +53 -55
- package/plugins/main/api/api.js +53 -55
- package/plugins/main/contact/contact.d.ts +2 -2
- package/plugins/main/endpoint/endpoint.d.ts +15 -15
- package/plugins/main/endpoint/endpoint.es6.js +7 -4
- package/plugins/main/endpoint/endpoint.js +7 -4
- package/plugins/main/host/host.d.ts +5 -5
- package/plugins/main/index.d.ts +2 -2
- package/plugins/main/index.es6.js +2 -2
- package/plugins/main/index.js +2 -2
- package/plugins/main/license/license.d.ts +5 -5
- package/plugins/main/param/param.d.ts +11 -11
- package/plugins/main/param/param.es6.js +3 -3
- package/plugins/main/param/param.js +3 -3
- 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/dev/dev.js → main/preset/preset.js} +9 -6
- 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 +18 -10
- package/plugins/main/response/response.js +18 -9
- package/plugins/main/return/index.d.ts +1 -0
- package/plugins/main/return/index.es6.js +1 -0
- package/plugins/main/return/index.js +9 -0
- package/plugins/main/return/return.d.ts +4 -0
- package/plugins/main/return/return.es6.js +10 -0
- package/plugins/main/return/return.js +14 -0
- package/plugins/main/server/server.d.ts +5 -5
- package/plugins/main/server/server.es6.js +36 -10
- package/plugins/main/server/server.js +36 -10
- package/plugins/main/tag/tag.d.ts +2 -2
- package/plugins/main/tag/tag.es6.js +5 -2
- package/plugins/main/tag/tag.js +5 -2
- package/plugins/main/variable/variable.d.ts +5 -5
- package/plugins/main/variable/variable.es6.js +3 -1
- package/plugins/main/variable/variable.js +3 -1
- package/plugins/request/cms/cms.es6.js +2 -2
- package/plugins/request/cms/cms.js +2 -2
- package/plugins/request/cookie/cookie.es6.js +3 -19
- package/plugins/request/cookie/cookie.js +3 -23
- package/plugins/request/error/error.d.ts +40 -40
- package/plugins/request/error/error.es6.js +45 -42
- package/plugins/request/error/error.js +45 -42
- package/plugins/request/file/file.es6.js +2 -3
- package/plugins/request/file/file.js +2 -3
- package/plugins/request/header/header.es6.js +1 -1
- package/plugins/request/header/header.js +1 -1
- package/plugins/request/proxy/proxy.d.ts +4 -1
- package/plugins/request/proxy/proxy.es6.js +5 -2
- package/plugins/request/proxy/proxy.js +5 -2
- package/plugins/request/redirect/redirect.d.ts +8 -7
- package/plugins/request/redirect/redirect.es6.js +7 -7
- package/plugins/request/redirect/redirect.js +7 -7
- package/plugins/request/success/success.d.ts +7 -6
- package/plugins/request/success/success.es6.js +21 -10
- package/plugins/request/success/success.js +21 -10
- 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/binary/binary.d.ts +3 -3
- package/plugins/schema/boolean/boolean.es6.js +2 -4
- package/plugins/schema/boolean/boolean.js +1 -3
- package/plugins/schema/date/date.d.ts +1 -1
- package/plugins/schema/date/date.es6.js +3 -3
- package/plugins/schema/date/date.js +3 -3
- package/plugins/schema/field/field.d.ts +1 -0
- package/plugins/schema/field/field.es6.js +7 -6
- package/plugins/schema/field/field.js +6 -5
- 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/integer/integer.d.ts +3 -3
- package/plugins/schema/integer/integer.es6.js +1 -1
- package/plugins/schema/integer/integer.js +1 -1
- package/plugins/schema/number/number.d.ts +2 -2
- package/plugins/schema/number/number.es6.js +1 -1
- package/plugins/schema/number/number.js +1 -1
- package/plugins/schema/object/object.es6.js +17 -4
- package/plugins/schema/object/object.js +17 -4
- package/plugins/schema/string/string.d.ts +2 -2
- package/plugins/schema/string/string.es6.js +44 -30
- package/plugins/schema/string/string.js +44 -30
- 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/{prod/prod.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 +15 -23
- package/utils/FileData/Bin.d.ts +13 -13
- package/utils/FileData/Bin.es6.js +2 -2
- package/utils/FileData/Bin.js +2 -2
- package/utils/action/Action.d.ts +17 -14
- package/utils/action/Action.es6.js +102 -78
- package/utils/action/Action.js +102 -78
- package/utils/dateFormat/dateFormat.d.ts +1 -1
- package/utils/dateFormat/dateFormat.es6.js +1 -1
- package/utils/dateFormat/dateFormat.js +1 -1
- package/utils/generateTypes/generateTypes.d.ts +3 -0
- package/utils/generateTypes/generateTypes.es6.js +157 -0
- package/utils/generateTypes/generateTypes.js +162 -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/getOrAdd/getOrAdd.d.ts +1 -1
- package/utils/httpOnStart/httpOnStart.d.ts +1 -1
- package/utils/httpOnStart/httpOnStart.es6.js +1 -1
- package/utils/httpOnStart/httpOnStart.js +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.es6.js +1 -0
- package/utils/index.js +1 -0
- package/utils/rules/binaryAccept/binaryAccept.es6.js +2 -2
- package/utils/rules/binaryAccept/binaryAccept.js +2 -2
- package/utils/rules/dateTo/dateTo.d.ts +1 -1
- package/utils/rules/helpers.d.ts +1 -1
- 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/int/int.es6.js +2 -2
- package/utils/rules/int/int.js +2 -2
- package/utils/rules/max/max.d.ts +1 -1
- package/utils/rules/max/max.es6.js +3 -3
- package/utils/rules/max/max.js +3 -3
- package/utils/rules/maxBin/maxBin.es6.js +2 -2
- package/utils/rules/maxBin/maxBin.js +2 -2
- package/utils/rules/maxDate/maxDate.es6.js +1 -1
- package/utils/rules/maxDate/maxDate.js +1 -1
- package/utils/rules/maxLength/maxLength.es6.js +2 -2
- package/utils/rules/maxLength/maxLength.js +2 -2
- package/utils/rules/min/min.d.ts +1 -1
- package/utils/rules/min/min.es6.js +3 -3
- package/utils/rules/min/min.js +3 -3
- package/utils/rules/minBin/minBin.es6.js +2 -2
- package/utils/rules/minBin/minBin.js +2 -2
- package/utils/rules/minDate/minDate.es6.js +1 -1
- package/utils/rules/minDate/minDate.js +1 -1
- package/utils/rules/minLength/minLength.es6.js +2 -2
- package/utils/rules/minLength/minLength.js +2 -2
- 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/utils/rules/pattern/pattern.d.ts +1 -1
- package/utils/rules/pattern/pattern.es6.js +2 -1
- package/utils/rules/pattern/pattern.js +2 -1
- package/example/app/App/App.d.ts +0 -1
- package/example/app/App/index.d.ts +0 -1
- package/example/index.d.ts +0 -1
- package/example/requests/index.d.ts +0 -1
- 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/app/ListSchema/ListSchema.d.ts +0 -1
- package/example/schemas/app/ListSchema/index.d.ts +0 -1
- package/example/schemas/app/index.d.ts +0 -1
- package/example/schemas/index.d.ts +0 -4
- 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/example/tags/index.d.ts +0 -1
- package/openApi.test.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/main/request/index.d.ts +0 -1
- package/plugins/main/request/index.es6.js +0 -1
- package/plugins/main/request/index.js +0 -9
- package/plugins/main/request/request.d.ts +0 -4
- package/plugins/main/request/request.es6.js +0 -21
- package/plugins/main/request/request.js +0 -25
- 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/decorators/once/once.test.d.ts +0 -1
- package/utils/parseSearch/parseSearch.test.d.ts +0 -1
- 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
|
+
<return>
|
|
85
|
+
<success>
|
|
86
|
+
Hello World!
|
|
87
|
+
</success>
|
|
88
|
+
</return>
|
|
89
|
+
</server>
|
|
90
|
+
)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
*Use `npm start` to run this server.*
|
|
94
|
+
|
|
95
|
+
Open http://localhost
|
|
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 (
|
|
@@ -88,7 +110,7 @@ export default (
|
|
|
88
110
|
|
|
89
111
|
*Use `npm start` to run this server.*
|
|
90
112
|
|
|
91
|
-
Open http://localhost
|
|
113
|
+
Open http://localhost
|
|
92
114
|
You will see a base Open API JSON structure.
|
|
93
115
|
|
|
94
116
|
```json
|
|
@@ -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
|
+
[\<return>](#return)
|
|
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
|
|
|
@@ -308,6 +345,235 @@ export default (
|
|
|
308
345
|
</server>
|
|
309
346
|
)
|
|
310
347
|
```
|
|
348
|
+
*default: `INNET_API_PREFIX` || `''`*
|
|
349
|
+
|
|
350
|
+
#### include
|
|
351
|
+
|
|
352
|
+
A regular expression scopes the API.
|
|
353
|
+
|
|
354
|
+
*src/app.tsx*
|
|
355
|
+
```typescript jsx
|
|
356
|
+
export default (
|
|
357
|
+
<server>
|
|
358
|
+
<api
|
|
359
|
+
include={/^\/(api|openapi)/}
|
|
360
|
+
/>
|
|
361
|
+
</server>
|
|
362
|
+
)
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
#### exclude
|
|
366
|
+
|
|
367
|
+
A regular expression does not scope the API.
|
|
368
|
+
|
|
369
|
+
*src/app.tsx*
|
|
370
|
+
```typescript jsx
|
|
371
|
+
export default (
|
|
372
|
+
<server>
|
|
373
|
+
<api prefix='/api' />
|
|
374
|
+
<api prefix='/openapi' />
|
|
375
|
+
<api exclude={/^\/(api|openapi)/} />
|
|
376
|
+
</server>
|
|
377
|
+
)
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
### \<return>
|
|
381
|
+
|
|
382
|
+
[← back](#main)
|
|
383
|
+
|
|
384
|
+
This element MUST be placed in [\<server>](#server) element.
|
|
385
|
+
It defines a run-time call handler for parent element.
|
|
386
|
+
|
|
387
|
+
*src/app.tsx*
|
|
388
|
+
```typescript jsx
|
|
389
|
+
export default (
|
|
390
|
+
<server>
|
|
391
|
+
<return>
|
|
392
|
+
<error status={404} />
|
|
393
|
+
</return>
|
|
394
|
+
</server>
|
|
395
|
+
)
|
|
396
|
+
```
|
|
397
|
+
*Any request returns 404*
|
|
398
|
+
|
|
399
|
+
The code runs from top to bottom and from left to right.
|
|
400
|
+
You cannot use two [\<return>](#return) elements one by one,
|
|
401
|
+
the same as you cannot use two `return` one by one for a JS `function`.
|
|
402
|
+
|
|
403
|
+
*src/app.tsx*
|
|
404
|
+
```typescript jsx
|
|
405
|
+
export default (
|
|
406
|
+
<server>
|
|
407
|
+
<return>
|
|
408
|
+
<error status={404} />
|
|
409
|
+
</return>
|
|
410
|
+
<return>
|
|
411
|
+
<success />
|
|
412
|
+
</return>
|
|
413
|
+
</server>
|
|
414
|
+
)
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
like
|
|
418
|
+
|
|
419
|
+
```javascript
|
|
420
|
+
function server () {
|
|
421
|
+
return 'error'
|
|
422
|
+
return 'success'
|
|
423
|
+
}
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
*The second [\<return>](#return) will newer run.*
|
|
427
|
+
|
|
428
|
+
You can use [\<return>](#return) in some elements like you use `return` in `if` or `while`.
|
|
429
|
+
|
|
430
|
+
*src/app.tsx*
|
|
431
|
+
```typescript jsx
|
|
432
|
+
export default (
|
|
433
|
+
<server>
|
|
434
|
+
<env is='dev'>
|
|
435
|
+
<return>
|
|
436
|
+
<error status={404} />
|
|
437
|
+
</return>
|
|
438
|
+
</env>
|
|
439
|
+
<return>
|
|
440
|
+
<success />
|
|
441
|
+
</return>
|
|
442
|
+
</server>
|
|
443
|
+
)
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
like
|
|
447
|
+
|
|
448
|
+
```javascript
|
|
449
|
+
function server () {
|
|
450
|
+
if (process.env.NODE_ENV === 'dev') {
|
|
451
|
+
return 'error'
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
return 'success'
|
|
455
|
+
}
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
Place [\<return>](#return) in [\<api>](#api) to handle any unknown request in the [\<api>](#api).
|
|
459
|
+
|
|
460
|
+
*src/app.tsx*
|
|
461
|
+
```typescript jsx
|
|
462
|
+
export default (
|
|
463
|
+
<server>
|
|
464
|
+
<api>
|
|
465
|
+
<return>
|
|
466
|
+
<error status={404} />
|
|
467
|
+
</return>
|
|
468
|
+
</api>
|
|
469
|
+
</server>
|
|
470
|
+
)
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
Place [\<return>](#return) in [\<endpoint>](#endpoint) to handle the [\<endpoint>](#endpoint) request.
|
|
474
|
+
|
|
475
|
+
*src/app.tsx*
|
|
476
|
+
```typescript jsx
|
|
477
|
+
export default (
|
|
478
|
+
<server>
|
|
479
|
+
<api>
|
|
480
|
+
<endpoint method='get' path='/my-endpoint'>
|
|
481
|
+
<return>
|
|
482
|
+
<success>
|
|
483
|
+
My Endpoint
|
|
484
|
+
</success>
|
|
485
|
+
</return>
|
|
486
|
+
</endpoint>
|
|
487
|
+
</api>
|
|
488
|
+
<return>
|
|
489
|
+
<success>
|
|
490
|
+
Any other request
|
|
491
|
+
</success>
|
|
492
|
+
</return>
|
|
493
|
+
</server>
|
|
494
|
+
)
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
You can place a component inside [\<return>](#return).
|
|
498
|
+
The component will run when the request will be triggered.
|
|
499
|
+
|
|
500
|
+
*src/app.tsx*
|
|
501
|
+
```typescript jsx
|
|
502
|
+
import { GetPartners } from './GetPartners'
|
|
503
|
+
|
|
504
|
+
export default (
|
|
505
|
+
<server>
|
|
506
|
+
<api>
|
|
507
|
+
<endpoint method='get' path='/partners'>
|
|
508
|
+
<return>
|
|
509
|
+
<GetPartners />
|
|
510
|
+
</return>
|
|
511
|
+
</endpoint>
|
|
512
|
+
</api>
|
|
513
|
+
</server>
|
|
514
|
+
)
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
*src/GetPartners.tsx*
|
|
518
|
+
```typescript jsx
|
|
519
|
+
export const GetPartners = () => (
|
|
520
|
+
<success>
|
|
521
|
+
{{partners: []}}
|
|
522
|
+
</success>
|
|
523
|
+
)
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
### \<preset>
|
|
527
|
+
|
|
528
|
+
[← back](#main)
|
|
529
|
+
|
|
530
|
+
`<preset>` element MUST be placed in `<server>` element.
|
|
531
|
+
This element adds handling of each request.
|
|
532
|
+
It works the same as [\<return>](#return), but do not interrupt the running.
|
|
533
|
+
You can use it to add a `header` or `cookie` or some setup of a parent element.
|
|
534
|
+
|
|
535
|
+
*src/app.tsx*
|
|
536
|
+
```typescript jsx
|
|
537
|
+
export default (
|
|
538
|
+
<server>
|
|
539
|
+
<preset>
|
|
540
|
+
<header
|
|
541
|
+
key='Test'
|
|
542
|
+
value='Ok'
|
|
543
|
+
/>
|
|
544
|
+
</preset>
|
|
545
|
+
</server>
|
|
546
|
+
)
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
Place the element inside [\<api>](#api) to preset it on the api requests scope.
|
|
550
|
+
|
|
551
|
+
*src/app.tsx*
|
|
552
|
+
```typescript jsx
|
|
553
|
+
export default (
|
|
554
|
+
<server>
|
|
555
|
+
<api prefix='/api'>
|
|
556
|
+
<preset>
|
|
557
|
+
<header
|
|
558
|
+
key='Cache-Control'
|
|
559
|
+
value='no-cache, no-store, must-revalidate'
|
|
560
|
+
/>
|
|
561
|
+
</preset>
|
|
562
|
+
...Endpoints
|
|
563
|
+
<return>
|
|
564
|
+
<success>
|
|
565
|
+
Header contains `Cache-Control`
|
|
566
|
+
</success>
|
|
567
|
+
</return>
|
|
568
|
+
</api>
|
|
569
|
+
<return>
|
|
570
|
+
<success>
|
|
571
|
+
Header do not contain `Cache-Control`
|
|
572
|
+
</success>
|
|
573
|
+
</return>
|
|
574
|
+
</server>
|
|
575
|
+
)
|
|
576
|
+
```
|
|
311
577
|
|
|
312
578
|
## Utils
|
|
313
579
|
|
|
@@ -316,102 +582,399 @@ This section contains elements of utils.
|
|
|
316
582
|
[← back](#index)
|
|
317
583
|
|
|
318
584
|
[\<swagger>](#swagger)
|
|
319
|
-
[\<
|
|
320
|
-
[\<dts>](#dts)
|
|
585
|
+
[\<env>](#env)
|
|
586
|
+
[\<dts>](#dts)
|
|
587
|
+
[\<blacklist>](#blacklist)
|
|
588
|
+
[\<whitelist>](#whitelist)
|
|
589
|
+
[\<protection>](#protection)
|
|
321
590
|
|
|
322
591
|
---
|
|
323
592
|
|
|
324
|
-
### \<swagger>
|
|
593
|
+
### \<swagger>
|
|
594
|
+
|
|
595
|
+
[← back](#utils)
|
|
596
|
+
|
|
597
|
+
Use `<swagger>` element to add Swagger UI documentation.
|
|
598
|
+
`<swagger>` element MUST be placed in `<api>` element.
|
|
599
|
+
|
|
600
|
+
*src/app.tsx*
|
|
601
|
+
```typescript jsx
|
|
602
|
+
export default (
|
|
603
|
+
<server>
|
|
604
|
+
<api>
|
|
605
|
+
<swagger />
|
|
606
|
+
</api>
|
|
607
|
+
</server>
|
|
608
|
+
)
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
Open http://localhost:80/swagger-ui
|
|
612
|
+
You will see Swagger UI documentation.
|
|
613
|
+
|
|
614
|
+
You can change the Swagger UI URL path by `path` property of `<swagger>` element.
|
|
615
|
+
|
|
616
|
+
*src/app.tsx*
|
|
617
|
+
```typescript jsx
|
|
618
|
+
export default (
|
|
619
|
+
<server>
|
|
620
|
+
<api>
|
|
621
|
+
<swagger path='/swagger' />
|
|
622
|
+
</api>
|
|
623
|
+
</server>
|
|
624
|
+
)
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
### \<env>
|
|
628
|
+
|
|
629
|
+
[← back](#utils)
|
|
630
|
+
|
|
631
|
+
This element helps to control content by `process.env`.
|
|
632
|
+
|
|
633
|
+
There are a required field of `is`.
|
|
634
|
+
If it's a `string` then an environment variable must be equal to the `string`.
|
|
635
|
+
If it's an `array of string` then an environment variable must be included into the `array of string`.
|
|
636
|
+
|
|
637
|
+
*src/app.tsx*
|
|
638
|
+
```typescript jsx
|
|
639
|
+
export default (
|
|
640
|
+
<server>
|
|
641
|
+
<api>
|
|
642
|
+
<env is='dev'>
|
|
643
|
+
<swagger />
|
|
644
|
+
</env>
|
|
645
|
+
</api>
|
|
646
|
+
</server>
|
|
647
|
+
)
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
*The `<swagger />` will work only if `NODE_ENV` equals `dev`*
|
|
651
|
+
|
|
652
|
+
#### of
|
|
653
|
+
|
|
654
|
+
By default `of` equals `NODE_ENV`. You can check eny other environment variable.
|
|
655
|
+
|
|
656
|
+
*src/app.tsx*
|
|
657
|
+
```typescript jsx
|
|
658
|
+
export default (
|
|
659
|
+
<server>
|
|
660
|
+
<api>
|
|
661
|
+
<env
|
|
662
|
+
of='PORT'
|
|
663
|
+
is={[
|
|
664
|
+
'3000',
|
|
665
|
+
'8080',
|
|
666
|
+
]}>
|
|
667
|
+
<swagger />
|
|
668
|
+
</env>
|
|
669
|
+
</api>
|
|
670
|
+
</server>
|
|
671
|
+
)
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
### \<dts>
|
|
675
|
+
|
|
676
|
+
[← back](#utils)
|
|
677
|
+
|
|
678
|
+
Use `<dts>` element to add types generation.
|
|
679
|
+
`<dts>` element MUST be placed in `<api>` element.
|
|
680
|
+
|
|
681
|
+
*src/app.tsx*
|
|
682
|
+
```typescript jsx
|
|
683
|
+
export default (
|
|
684
|
+
<server>
|
|
685
|
+
<api>
|
|
686
|
+
<dts />
|
|
687
|
+
</api>
|
|
688
|
+
</server>
|
|
689
|
+
)
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
You do not need to import types, use `Api` namespace everywhere.
|
|
693
|
+
Here is an example of generated types usage.
|
|
694
|
+
|
|
695
|
+
```typescript jsx
|
|
696
|
+
import { useParams } from '@innet/server'
|
|
697
|
+
|
|
698
|
+
import { todos } from '../todos'
|
|
699
|
+
|
|
700
|
+
export function DeleteTodo () {
|
|
701
|
+
const { todoId } = useParams<Api.Endpoints['DELETE:/todos/{todoId}']['Params']>()
|
|
702
|
+
|
|
703
|
+
const todoIndex = todos.findIndex(({ id }) => id === todoId)
|
|
704
|
+
|
|
705
|
+
if (todoIndex === -1) {
|
|
706
|
+
return <error code='todoNotFound' status={404} />
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
todos.splice(todoIndex, 1)
|
|
710
|
+
|
|
711
|
+
return <success />
|
|
712
|
+
}
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
#### path
|
|
716
|
+
|
|
717
|
+
This is a path of api TypeScript types file, `<dts>` generates it.
|
|
718
|
+
`'src/api.d.ts'` by default.
|
|
719
|
+
|
|
720
|
+
*src/app.tsx*
|
|
721
|
+
```typescript jsx
|
|
722
|
+
export default (
|
|
723
|
+
<server>
|
|
724
|
+
<api>
|
|
725
|
+
<dts path='src/types.d.ts' />
|
|
726
|
+
</api>
|
|
727
|
+
</server>
|
|
728
|
+
)
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
#### namespace
|
|
732
|
+
|
|
733
|
+
This prop changes namespace for generated types. `'Api'` by default.
|
|
734
|
+
|
|
735
|
+
*src/app.tsx*
|
|
736
|
+
```typescript jsx
|
|
737
|
+
export default (
|
|
738
|
+
<server>
|
|
739
|
+
<api>
|
|
740
|
+
<dts namespace='API' />
|
|
741
|
+
</api>
|
|
742
|
+
</server>
|
|
743
|
+
)
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
### \<blacklist>
|
|
747
|
+
|
|
748
|
+
This element MUST be placed in `<api>` element.
|
|
749
|
+
|
|
750
|
+
[← back](#utils)
|
|
751
|
+
|
|
752
|
+
This element returns own content for a user from IPs list.
|
|
753
|
+
|
|
754
|
+
*src/app.tsx*
|
|
755
|
+
```typescript jsx
|
|
756
|
+
export default (
|
|
757
|
+
<server>
|
|
758
|
+
<api>
|
|
759
|
+
<blacklist>
|
|
760
|
+
<error />
|
|
761
|
+
</blacklist>
|
|
762
|
+
</api>
|
|
763
|
+
</server>
|
|
764
|
+
)
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
#### ip
|
|
768
|
+
|
|
769
|
+
`ip` prop sets black IPs. By default, it equals `INNET_BLACKLIST_IP` node environment variable.
|
|
770
|
+
|
|
771
|
+
You can split IPs by `,` char.
|
|
772
|
+
|
|
773
|
+
*src/app.tsx*
|
|
774
|
+
```typescript jsx
|
|
775
|
+
export default (
|
|
776
|
+
<server>
|
|
777
|
+
<api>
|
|
778
|
+
<blacklist
|
|
779
|
+
ip='0.1.2.3,3.2.1.0'>
|
|
780
|
+
<error />
|
|
781
|
+
</blacklist>
|
|
782
|
+
</api>
|
|
783
|
+
</server>
|
|
784
|
+
)
|
|
785
|
+
```
|
|
786
|
+
|
|
787
|
+
### \<whitelist>
|
|
788
|
+
|
|
789
|
+
This element MUST be placed in `<api>` element.
|
|
790
|
+
|
|
791
|
+
[← back](#utils)
|
|
792
|
+
|
|
793
|
+
This element returns own content for a user IP, which is not in a list.
|
|
794
|
+
|
|
795
|
+
*src/app.tsx*
|
|
796
|
+
```typescript jsx
|
|
797
|
+
export default (
|
|
798
|
+
<server>
|
|
799
|
+
<api>
|
|
800
|
+
<whitelist>
|
|
801
|
+
<error />
|
|
802
|
+
</whitelist>
|
|
803
|
+
</api>
|
|
804
|
+
</server>
|
|
805
|
+
)
|
|
806
|
+
```
|
|
807
|
+
|
|
808
|
+
#### ip
|
|
809
|
+
|
|
810
|
+
`ip` prop sets white IPs. By default, it equals `INNET_WHITELIST_IP` node environment variable.
|
|
811
|
+
|
|
812
|
+
You can split IPs by `,` char.
|
|
813
|
+
|
|
814
|
+
*src/app.tsx*
|
|
815
|
+
```typescript jsx
|
|
816
|
+
export default (
|
|
817
|
+
<server>
|
|
818
|
+
<api>
|
|
819
|
+
<whitelist
|
|
820
|
+
ip='0.1.2.3,3.2.1.0'>
|
|
821
|
+
<error />
|
|
822
|
+
</whitelist>
|
|
823
|
+
</api>
|
|
824
|
+
</server>
|
|
825
|
+
)
|
|
826
|
+
```
|
|
827
|
+
|
|
828
|
+
### \<protection>
|
|
829
|
+
|
|
830
|
+
This element MUST be placed in `<api>` element.
|
|
831
|
+
|
|
832
|
+
[← back](#utils)
|
|
833
|
+
|
|
834
|
+
This element adds protection page.
|
|
835
|
+
You can use it when you want to protect your application.
|
|
836
|
+
|
|
837
|
+
If protection failed content of the element should be used.
|
|
838
|
+
|
|
839
|
+
*src/app.tsx*
|
|
840
|
+
```typescript jsx
|
|
841
|
+
export default (
|
|
842
|
+
<server>
|
|
843
|
+
<api>
|
|
844
|
+
<protection>
|
|
845
|
+
<error
|
|
846
|
+
code='protection'
|
|
847
|
+
status='forbidden'
|
|
848
|
+
/>
|
|
849
|
+
</protection>
|
|
850
|
+
</api>
|
|
851
|
+
</server>
|
|
852
|
+
)
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
#### value
|
|
856
|
+
|
|
857
|
+
This prop is a secret string of protection value.
|
|
858
|
+
User must provide a protection query param equals the `value`.
|
|
859
|
+
|
|
860
|
+
By default, the value is `undefined` and protection does not work.
|
|
861
|
+
You can use `PROTECTION` env to set default protection `value`.
|
|
862
|
+
|
|
863
|
+
*src/app.tsx*
|
|
864
|
+
```typescript jsx
|
|
865
|
+
export default (
|
|
866
|
+
<server>
|
|
867
|
+
<api>
|
|
868
|
+
<protection value='secret'>
|
|
869
|
+
<error
|
|
870
|
+
code='protection'
|
|
871
|
+
status='forbidden'
|
|
872
|
+
/>
|
|
873
|
+
</protection>
|
|
874
|
+
</api>
|
|
875
|
+
</server>
|
|
876
|
+
)
|
|
877
|
+
```
|
|
878
|
+
|
|
879
|
+
#### maxAge
|
|
325
880
|
|
|
326
|
-
|
|
881
|
+
This prop sets how much time protection is qualified.
|
|
327
882
|
|
|
328
|
-
|
|
329
|
-
|
|
883
|
+
By default, the prop equals a year.
|
|
884
|
+
You can use `INNET_PROTECTION_MAX_AGE` env to set default `maxAge`.
|
|
330
885
|
|
|
331
886
|
*src/app.tsx*
|
|
332
887
|
```typescript jsx
|
|
333
888
|
export default (
|
|
334
889
|
<server>
|
|
335
890
|
<api>
|
|
336
|
-
<
|
|
891
|
+
<protection
|
|
892
|
+
maxAge={24 * 60 * 60}
|
|
893
|
+
value='secret'>
|
|
894
|
+
<error
|
|
895
|
+
code='protection'
|
|
896
|
+
status='forbidden'
|
|
897
|
+
/>
|
|
898
|
+
</protection>
|
|
337
899
|
</api>
|
|
338
900
|
</server>
|
|
339
901
|
)
|
|
340
902
|
```
|
|
341
903
|
|
|
342
|
-
|
|
343
|
-
You will see Swagger UI documentation.
|
|
904
|
+
#### excludeIp
|
|
344
905
|
|
|
345
|
-
|
|
906
|
+
This prop sets a list of IP addresses (split by `,`) to ignore the protection.
|
|
907
|
+
|
|
908
|
+
You can use `INNET_PROTECTED_IP` env to set default `excludeIp`.
|
|
346
909
|
|
|
347
910
|
*src/app.tsx*
|
|
348
911
|
```typescript jsx
|
|
349
912
|
export default (
|
|
350
913
|
<server>
|
|
351
914
|
<api>
|
|
352
|
-
<
|
|
915
|
+
<protection
|
|
916
|
+
excludeIp='0.0.0.0,127.0.0.0'
|
|
917
|
+
value='secret'>
|
|
918
|
+
<error
|
|
919
|
+
code='protection'
|
|
920
|
+
status='forbidden'
|
|
921
|
+
/>
|
|
922
|
+
</protection>
|
|
353
923
|
</api>
|
|
354
924
|
</server>
|
|
355
925
|
)
|
|
356
926
|
```
|
|
357
927
|
|
|
358
|
-
|
|
928
|
+
#### cookieKey
|
|
359
929
|
|
|
360
|
-
|
|
930
|
+
This prop sets a cookie field name used to store protection of a user.
|
|
361
931
|
|
|
362
|
-
|
|
932
|
+
By default, it equals `protection`.
|
|
933
|
+
You can use `INNET_PROTECTION_COOKIE_KEY` env to set default `cookieKey`.
|
|
363
934
|
|
|
364
935
|
*src/app.tsx*
|
|
365
936
|
```typescript jsx
|
|
366
937
|
export default (
|
|
367
938
|
<server>
|
|
368
939
|
<api>
|
|
369
|
-
<
|
|
370
|
-
|
|
371
|
-
|
|
940
|
+
<protection
|
|
941
|
+
cookieKey='secret'
|
|
942
|
+
value='secret'>
|
|
943
|
+
<error
|
|
944
|
+
code='protection'
|
|
945
|
+
status='forbidden'
|
|
946
|
+
/>
|
|
947
|
+
</protection>
|
|
372
948
|
</api>
|
|
373
949
|
</server>
|
|
374
950
|
)
|
|
375
951
|
```
|
|
376
952
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
[← back](#utils)
|
|
953
|
+
#### searchKey
|
|
380
954
|
|
|
381
|
-
|
|
382
|
-
`<dts>` element MUST be placed in `<api>` element.
|
|
955
|
+
This prop sets a search query field name used to check protection.
|
|
383
956
|
|
|
384
|
-
|
|
957
|
+
By default, it equals `protection`.
|
|
958
|
+
You can use `INNET_PROTECTION_SEARCH_KEY` env to set default `searchKey`.
|
|
385
959
|
|
|
386
960
|
*src/app.tsx*
|
|
387
961
|
```typescript jsx
|
|
388
962
|
export default (
|
|
389
963
|
<server>
|
|
390
964
|
<api>
|
|
391
|
-
<
|
|
392
|
-
|
|
393
|
-
|
|
965
|
+
<protection
|
|
966
|
+
searchKey='secret'
|
|
967
|
+
value='secret'>
|
|
968
|
+
<error
|
|
969
|
+
code='protection'
|
|
970
|
+
status='forbidden'
|
|
971
|
+
/>
|
|
972
|
+
</protection>
|
|
394
973
|
</api>
|
|
395
974
|
</server>
|
|
396
975
|
)
|
|
397
976
|
```
|
|
398
977
|
|
|
399
|
-
> You MUST add some [endpoint](#endpoint) with some schema otherwise you get the `Error: There is no schema in the input contents`.
|
|
400
|
-
|
|
401
|
-
Here is an example of generated types usage.
|
|
402
|
-
|
|
403
|
-
*src/GetPartner.tsx*
|
|
404
|
-
```typescript jsx
|
|
405
|
-
import { useParams } from '@innet/server'
|
|
406
|
-
|
|
407
|
-
export function GetPartner () {
|
|
408
|
-
const { id } = useParams<Paths.Partners$Id.Get.PathParameters>()
|
|
409
|
-
return <success>{{ id }}</success>
|
|
410
|
-
}
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
You do not need to import types, they generate as namespaces.
|
|
414
|
-
|
|
415
978
|
## API Info
|
|
416
979
|
|
|
417
980
|
The API information elements are here.
|
|
@@ -860,171 +1423,430 @@ export default (
|
|
|
860
1423
|
)
|
|
861
1424
|
```
|
|
862
1425
|
|
|
863
|
-
### \<param>
|
|
864
|
-
|
|
865
|
-
[← back](#endpoints)
|
|
866
|
-
|
|
867
|
-
Describes a single operation parameter.
|
|
1426
|
+
### \<param>
|
|
1427
|
+
|
|
1428
|
+
[← back](#endpoints)
|
|
1429
|
+
|
|
1430
|
+
Describes a single operation parameter.
|
|
1431
|
+
|
|
1432
|
+
A unique parameter is defined by a combination of a `name` and location.
|
|
1433
|
+
|
|
1434
|
+
##### Parameter Locations
|
|
1435
|
+
|
|
1436
|
+
There are four possible parameter locations specified by the `in` prop:
|
|
1437
|
+
|
|
1438
|
+
- **path** - Used together with [Path Templating](https://swagger.io/specification/#path-templating), where the parameter value is actually part of the operation's URL.
|
|
1439
|
+
This does not include the host or base path of the API. For example, in `/items/{itemId}`, the path parameter is `itemId`.
|
|
1440
|
+
- **query** - Parameters that are appended to the URL. For example, in `/items?id=###`, the query parameter is `id`.
|
|
1441
|
+
- **header** - Custom headers that are expected as part of the request. Note that RFC7230 states header names are case insensitive.
|
|
1442
|
+
- **cookie** - Used to pass a specific cookie value to the API.
|
|
1443
|
+
|
|
1444
|
+
#### in
|
|
1445
|
+
|
|
1446
|
+
The location of the parameter.
|
|
1447
|
+
Possible values are `"query"`, `"header"`, `"path"` or `"cookie"`.
|
|
1448
|
+
|
|
1449
|
+
#### name
|
|
1450
|
+
|
|
1451
|
+
The name of the parameter. Parameter names are *case sensitive*.
|
|
1452
|
+
|
|
1453
|
+
- If `in` is "path", the `name` field MUST correspond to a template expression occurring within the `path` field in the `endpoint`. See [Path Templating](https://swagger.io/specification/#path-templating) for further information.
|
|
1454
|
+
- If `in` is "header" and the `name` field is "Accept", "Content-Type" or "Authorization", the parameter definition SHALL be ignored.
|
|
1455
|
+
- For all other cases, the `name` corresponds to the parameter name used by the `in` property.
|
|
1456
|
+
|
|
1457
|
+
*src/app.tsx*
|
|
1458
|
+
```typescript jsx
|
|
1459
|
+
export default (
|
|
1460
|
+
<server>
|
|
1461
|
+
<api>
|
|
1462
|
+
<endpoint method='get' path='/users/{userId}'>
|
|
1463
|
+
<param in='path' name='userId' />
|
|
1464
|
+
</endpoint>
|
|
1465
|
+
</api>
|
|
1466
|
+
</server>
|
|
1467
|
+
)
|
|
1468
|
+
```
|
|
1469
|
+
|
|
1470
|
+
#### description
|
|
1471
|
+
|
|
1472
|
+
A brief description of the parameter.
|
|
1473
|
+
This could contain examples of use.
|
|
1474
|
+
[CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
1475
|
+
|
|
1476
|
+
*src/app.tsx*
|
|
1477
|
+
```typescript jsx
|
|
1478
|
+
export default (
|
|
1479
|
+
<server>
|
|
1480
|
+
<api>
|
|
1481
|
+
<endpoint method='get' path='/users/{userId}'>
|
|
1482
|
+
<param
|
|
1483
|
+
in='path'
|
|
1484
|
+
name='userId'
|
|
1485
|
+
description='User identification number'
|
|
1486
|
+
/>
|
|
1487
|
+
</endpoint>
|
|
1488
|
+
</api>
|
|
1489
|
+
</server>
|
|
1490
|
+
)
|
|
1491
|
+
```
|
|
1492
|
+
|
|
1493
|
+
#### required
|
|
1494
|
+
|
|
1495
|
+
Determines whether this parameter is mandatory.
|
|
1496
|
+
If the parameter location is "path", this property is `true` and its value MUST be `true`.
|
|
1497
|
+
Otherwise, the property MAY be included and its default value is `false`.
|
|
1498
|
+
|
|
1499
|
+
*src/app.tsx*
|
|
1500
|
+
```typescript jsx
|
|
1501
|
+
export default (
|
|
1502
|
+
<server>
|
|
1503
|
+
<api>
|
|
1504
|
+
<endpoint method='get' path='/users'>
|
|
1505
|
+
<param
|
|
1506
|
+
in='cookie'
|
|
1507
|
+
name='token'
|
|
1508
|
+
required
|
|
1509
|
+
/>
|
|
1510
|
+
</endpoint>
|
|
1511
|
+
</api>
|
|
1512
|
+
</server>
|
|
1513
|
+
)
|
|
1514
|
+
```
|
|
1515
|
+
|
|
1516
|
+
#### deprecated
|
|
1517
|
+
|
|
1518
|
+
Specifies that a parameter is deprecated and SHOULD be transitioned out of usage.
|
|
1519
|
+
Default value is `false`.
|
|
1520
|
+
|
|
1521
|
+
*src/app.tsx*
|
|
1522
|
+
```typescript jsx
|
|
1523
|
+
export default (
|
|
1524
|
+
<server>
|
|
1525
|
+
<api>
|
|
1526
|
+
<endpoint method='get' path='/users'>
|
|
1527
|
+
<param
|
|
1528
|
+
in='query'
|
|
1529
|
+
name='status'
|
|
1530
|
+
deprecated
|
|
1531
|
+
/>
|
|
1532
|
+
</endpoint>
|
|
1533
|
+
</api>
|
|
1534
|
+
</server>
|
|
1535
|
+
)
|
|
1536
|
+
```
|
|
1537
|
+
|
|
1538
|
+
### \<body>
|
|
1539
|
+
|
|
1540
|
+
[← back](#endpoints)
|
|
1541
|
+
|
|
1542
|
+
This element MUST be placed inside `<endpoint>`.
|
|
1543
|
+
It defines request body for the endpoint.
|
|
1544
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
1545
|
+
|
|
1546
|
+
*src/app.tsx*
|
|
1547
|
+
```typescript jsx
|
|
1548
|
+
return (
|
|
1549
|
+
<server>
|
|
1550
|
+
<api>
|
|
1551
|
+
<endpoint method='post' path='/partners'>
|
|
1552
|
+
<body>
|
|
1553
|
+
<object>
|
|
1554
|
+
<field key='name'>
|
|
1555
|
+
<string example='CANTent.' />
|
|
1556
|
+
</field>
|
|
1557
|
+
<field key='gift'>
|
|
1558
|
+
<boolean />
|
|
1559
|
+
</field>
|
|
1560
|
+
<field optional key='addresses'>
|
|
1561
|
+
<array>
|
|
1562
|
+
<number description='address id' />
|
|
1563
|
+
</array>
|
|
1564
|
+
</field>
|
|
1565
|
+
</object>
|
|
1566
|
+
</body>
|
|
1567
|
+
</endpoint>
|
|
1568
|
+
</api>
|
|
1569
|
+
</server>
|
|
1570
|
+
)
|
|
1571
|
+
```
|
|
1572
|
+
|
|
1573
|
+
### \<response>
|
|
1574
|
+
|
|
1575
|
+
[← back](#endpoints)
|
|
1576
|
+
|
|
1577
|
+
This element MUST be placed inside `<endpoint>`.
|
|
1578
|
+
It defines response body for the endpoint.
|
|
1579
|
+
|
|
1580
|
+
*src/app.tsx*
|
|
1581
|
+
```typescript jsx
|
|
1582
|
+
return (
|
|
1583
|
+
<server>
|
|
1584
|
+
<api>
|
|
1585
|
+
<endpoint method='get' path='/settings'>
|
|
1586
|
+
<response>
|
|
1587
|
+
<object />
|
|
1588
|
+
</response>
|
|
1589
|
+
</endpoint>
|
|
1590
|
+
</api>
|
|
1591
|
+
</server>
|
|
1592
|
+
)
|
|
1593
|
+
```
|
|
1594
|
+
|
|
1595
|
+
#### status
|
|
1596
|
+
A status of the `<response>`.
|
|
1597
|
+
Any [HTTP status code](https://swagger.io/specification/#http-codes) can be used as a number of the property.
|
|
1598
|
+
|
|
1599
|
+
By default, `status` equals `'default'`.
|
|
1600
|
+
|
|
1601
|
+
*src/app.tsx*
|
|
1602
|
+
```typescript jsx
|
|
1603
|
+
return (
|
|
1604
|
+
<server>
|
|
1605
|
+
<api>
|
|
1606
|
+
<endpoint method='get' path='/settings'>
|
|
1607
|
+
<response status={200}>
|
|
1608
|
+
<object />
|
|
1609
|
+
</response>
|
|
1610
|
+
</endpoint>
|
|
1611
|
+
</api>
|
|
1612
|
+
</server>
|
|
1613
|
+
)
|
|
1614
|
+
```
|
|
1615
|
+
|
|
1616
|
+
To define a range of response codes, this field MAY contain the uppercase wildcard character `X`.
|
|
1617
|
+
For example, `2XX` represents all response codes between \[200-299].
|
|
1618
|
+
Only the following range definitions are allowed: `1XX`, `2XX`, `3XX`, `4XX` and `5XX`.
|
|
1619
|
+
|
|
1620
|
+
*src/app.tsx*
|
|
1621
|
+
```typescript jsx
|
|
1622
|
+
return (
|
|
1623
|
+
<server>
|
|
1624
|
+
<api>
|
|
1625
|
+
<endpoint method='get' path='/settings'>
|
|
1626
|
+
<response status='2XX'>
|
|
1627
|
+
<object />
|
|
1628
|
+
</response>
|
|
1629
|
+
</endpoint>
|
|
1630
|
+
</api>
|
|
1631
|
+
</server>
|
|
1632
|
+
)
|
|
1633
|
+
```
|
|
1634
|
+
|
|
1635
|
+
Many number statuses have a string id you can use on the property.
|
|
1636
|
+
|
|
1637
|
+
*src/app.tsx*
|
|
1638
|
+
```typescript jsx
|
|
1639
|
+
return (
|
|
1640
|
+
<server>
|
|
1641
|
+
<api>
|
|
1642
|
+
<endpoint method='get' path='/settings'>
|
|
1643
|
+
<response status='notFound'>
|
|
1644
|
+
<object />
|
|
1645
|
+
</response>
|
|
1646
|
+
</endpoint>
|
|
1647
|
+
</api>
|
|
1648
|
+
</server>
|
|
1649
|
+
)
|
|
1650
|
+
```
|
|
1651
|
+
|
|
1652
|
+
You can use many `<response>` elements in an endpoint.
|
|
1653
|
+
|
|
1654
|
+
*src/app.tsx*
|
|
1655
|
+
```typescript jsx
|
|
1656
|
+
return (
|
|
1657
|
+
<server>
|
|
1658
|
+
<api>
|
|
1659
|
+
<endpoint method='get' path='/settings'>
|
|
1660
|
+
<response status='2XX'>
|
|
1661
|
+
<object />
|
|
1662
|
+
</response>
|
|
1663
|
+
<response status='4XX'>
|
|
1664
|
+
<object>
|
|
1665
|
+
<field key='error'>
|
|
1666
|
+
<string />
|
|
1667
|
+
</field>
|
|
1668
|
+
<field optional key='data'>
|
|
1669
|
+
<object />
|
|
1670
|
+
</field>
|
|
1671
|
+
</object>
|
|
1672
|
+
</response>
|
|
1673
|
+
</endpoint>
|
|
1674
|
+
</api>
|
|
1675
|
+
</server>
|
|
1676
|
+
)
|
|
1677
|
+
```
|
|
1678
|
+
|
|
1679
|
+
#### type
|
|
1680
|
+
A media type of the `<response>`.
|
|
868
1681
|
|
|
869
|
-
|
|
1682
|
+
By default, `type` equals `'application/json'`.
|
|
870
1683
|
|
|
871
|
-
|
|
1684
|
+
*src/app.tsx*
|
|
1685
|
+
```typescript jsx
|
|
1686
|
+
return (
|
|
1687
|
+
<server>
|
|
1688
|
+
<api>
|
|
1689
|
+
<endpoint method='get' path='/hello'>
|
|
1690
|
+
<response type='text/html'>
|
|
1691
|
+
Hello World!
|
|
1692
|
+
</response>
|
|
1693
|
+
</endpoint>
|
|
1694
|
+
</api>
|
|
1695
|
+
</server>
|
|
1696
|
+
)
|
|
1697
|
+
```
|
|
872
1698
|
|
|
873
|
-
|
|
1699
|
+
## Primitive Data
|
|
874
1700
|
|
|
875
|
-
|
|
876
|
-
This does not include the host or base path of the API. For example, in `/items/{itemId}`, the path parameter is `itemId`.
|
|
877
|
-
- **query** - Parameters that are appended to the URL. For example, in `/items?id=###`, the query parameter is `id`.
|
|
878
|
-
- **header** - Custom headers that are expected as part of the request. Note that RFC7230 states header names are case insensitive.
|
|
879
|
-
- **cookie** - Used to pass a specific cookie value to the API.
|
|
1701
|
+
[← back](#index)
|
|
880
1702
|
|
|
881
|
-
|
|
1703
|
+
[\<any>](#any)
|
|
1704
|
+
[\<null>](#null)
|
|
1705
|
+
[\<boolean>](#boolean)
|
|
1706
|
+
[\<string>](#string)
|
|
1707
|
+
[\<number>](#number)
|
|
1708
|
+
[\<integer>](#integer)
|
|
1709
|
+
[\<date>](#date)
|
|
1710
|
+
[\<uuid>](#uuid)
|
|
1711
|
+
[\<binary>](#binary)
|
|
882
1712
|
|
|
883
|
-
|
|
884
|
-
Possible values are `"query"`, `"header"`, `"path"` or `"cookie"`.
|
|
1713
|
+
---
|
|
885
1714
|
|
|
886
|
-
|
|
1715
|
+
### \<any>
|
|
887
1716
|
|
|
888
|
-
|
|
1717
|
+
[← back](#primitive-data)
|
|
889
1718
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
1719
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
1720
|
+
It defines `any` value for a parent element.
|
|
1721
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
893
1722
|
|
|
894
1723
|
*src/app.tsx*
|
|
895
1724
|
```typescript jsx
|
|
896
1725
|
export default (
|
|
897
1726
|
<server>
|
|
898
1727
|
<api>
|
|
899
|
-
<endpoint method='get' path='/
|
|
900
|
-
<param
|
|
1728
|
+
<endpoint method='get' path='/todos'>
|
|
1729
|
+
<param
|
|
1730
|
+
in='query'
|
|
1731
|
+
name='search'>
|
|
1732
|
+
<any />
|
|
1733
|
+
</param>
|
|
901
1734
|
</endpoint>
|
|
902
1735
|
</api>
|
|
903
1736
|
</server>
|
|
904
1737
|
)
|
|
905
1738
|
```
|
|
906
1739
|
|
|
907
|
-
####
|
|
1740
|
+
#### default
|
|
908
1741
|
|
|
909
|
-
A
|
|
910
|
-
This could contain examples of use.
|
|
911
|
-
[CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
1742
|
+
A default value for the `any`.
|
|
912
1743
|
|
|
913
1744
|
*src/app.tsx*
|
|
914
1745
|
```typescript jsx
|
|
915
1746
|
export default (
|
|
916
1747
|
<server>
|
|
917
1748
|
<api>
|
|
918
|
-
<endpoint method='get' path='/users
|
|
1749
|
+
<endpoint method='get' path='/users'>
|
|
919
1750
|
<param
|
|
920
|
-
in='
|
|
921
|
-
name='
|
|
922
|
-
|
|
923
|
-
|
|
1751
|
+
in='query'
|
|
1752
|
+
name='search'>
|
|
1753
|
+
<any default={null} />
|
|
1754
|
+
</param>
|
|
924
1755
|
</endpoint>
|
|
925
1756
|
</api>
|
|
926
1757
|
</server>
|
|
927
1758
|
)
|
|
928
1759
|
```
|
|
929
1760
|
|
|
930
|
-
####
|
|
1761
|
+
#### example
|
|
931
1762
|
|
|
932
|
-
|
|
933
|
-
If the parameter location is "path", this property is `true` and its value MUST be `true`.
|
|
934
|
-
Otherwise, the property MAY be included and its default value is `false`.
|
|
1763
|
+
An example value.
|
|
935
1764
|
|
|
936
1765
|
*src/app.tsx*
|
|
937
1766
|
```typescript jsx
|
|
938
1767
|
export default (
|
|
939
1768
|
<server>
|
|
940
1769
|
<api>
|
|
941
|
-
<endpoint method='get' path='/
|
|
1770
|
+
<endpoint method='get' path='/products'>
|
|
942
1771
|
<param
|
|
943
|
-
in='
|
|
944
|
-
name='
|
|
945
|
-
|
|
946
|
-
|
|
1772
|
+
in='query'
|
|
1773
|
+
name='active'>
|
|
1774
|
+
<any example={false} />
|
|
1775
|
+
</param>
|
|
947
1776
|
</endpoint>
|
|
948
1777
|
</api>
|
|
949
1778
|
</server>
|
|
950
1779
|
)
|
|
951
1780
|
```
|
|
952
1781
|
|
|
953
|
-
####
|
|
1782
|
+
#### description
|
|
954
1783
|
|
|
955
|
-
|
|
956
|
-
Default value is `false`.
|
|
1784
|
+
A description of the `any`.
|
|
957
1785
|
|
|
958
1786
|
*src/app.tsx*
|
|
959
1787
|
```typescript jsx
|
|
960
1788
|
export default (
|
|
961
1789
|
<server>
|
|
962
1790
|
<api>
|
|
963
|
-
<endpoint method='get' path='/
|
|
1791
|
+
<endpoint method='get' path='/products'>
|
|
964
1792
|
<param
|
|
965
1793
|
in='query'
|
|
966
|
-
name='
|
|
967
|
-
|
|
968
|
-
|
|
1794
|
+
name='active'>
|
|
1795
|
+
<any
|
|
1796
|
+
description='Active products param'
|
|
1797
|
+
/>
|
|
1798
|
+
</param>
|
|
969
1799
|
</endpoint>
|
|
970
1800
|
</api>
|
|
971
1801
|
</server>
|
|
972
1802
|
)
|
|
973
1803
|
```
|
|
974
1804
|
|
|
975
|
-
### \<
|
|
1805
|
+
### \<null>
|
|
976
1806
|
|
|
977
|
-
[← back](#
|
|
1807
|
+
[← back](#primitive-data)
|
|
978
1808
|
|
|
979
|
-
|
|
980
|
-
It defines
|
|
1809
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
1810
|
+
It defines `null` value for a parent element.
|
|
981
1811
|
`@innet/server` formats and validate the value automatically (real-time).
|
|
982
1812
|
|
|
1813
|
+
*src/app.tsx*
|
|
983
1814
|
```typescript jsx
|
|
984
|
-
|
|
1815
|
+
export default (
|
|
985
1816
|
<server>
|
|
986
1817
|
<api>
|
|
987
|
-
<endpoint method='
|
|
988
|
-
<
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
<field key='gift'>
|
|
994
|
-
<boolean />
|
|
995
|
-
</field>
|
|
996
|
-
<field optional key='addresses'>
|
|
997
|
-
<array>
|
|
998
|
-
<number description='address id' />
|
|
999
|
-
</array>
|
|
1000
|
-
</field>
|
|
1001
|
-
</object>
|
|
1002
|
-
</body>
|
|
1818
|
+
<endpoint method='get' path='/todos'>
|
|
1819
|
+
<param
|
|
1820
|
+
in='query'
|
|
1821
|
+
name='search'>
|
|
1822
|
+
<null />
|
|
1823
|
+
</param>
|
|
1003
1824
|
</endpoint>
|
|
1004
1825
|
</api>
|
|
1005
1826
|
</server>
|
|
1006
1827
|
)
|
|
1007
1828
|
```
|
|
1008
1829
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
[← back](#endpoints)
|
|
1012
|
-
|
|
1013
|
-
This element MUST be placed inside `<endpoint>`.
|
|
1014
|
-
It defines response body for the endpoint.
|
|
1015
|
-
|
|
1016
|
-
## Primitive Data
|
|
1830
|
+
#### description
|
|
1017
1831
|
|
|
1018
|
-
|
|
1832
|
+
A description of the `null`.
|
|
1019
1833
|
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1834
|
+
*src/app.tsx*
|
|
1835
|
+
```typescript jsx
|
|
1836
|
+
export default (
|
|
1837
|
+
<server>
|
|
1838
|
+
<api>
|
|
1839
|
+
<endpoint method='get' path='/products'>
|
|
1840
|
+
<param
|
|
1841
|
+
in='query'
|
|
1842
|
+
name='active'>
|
|
1843
|
+
<null description='FIXME!' />
|
|
1844
|
+
</param>
|
|
1845
|
+
</endpoint>
|
|
1846
|
+
</api>
|
|
1847
|
+
</server>
|
|
1848
|
+
)
|
|
1849
|
+
```
|
|
1028
1850
|
|
|
1029
1851
|
### \<boolean>
|
|
1030
1852
|
|
|
@@ -2306,7 +3128,9 @@ export default (
|
|
|
2306
3128
|
<api>
|
|
2307
3129
|
<endpoint method='post' path='/users'>
|
|
2308
3130
|
<body>
|
|
2309
|
-
<object
|
|
3131
|
+
<object>
|
|
3132
|
+
<string />
|
|
3133
|
+
</object>
|
|
2310
3134
|
</body>
|
|
2311
3135
|
</endpoint>
|
|
2312
3136
|
</api>
|
|
@@ -2367,9 +3191,9 @@ export default (
|
|
|
2367
3191
|
<api>
|
|
2368
3192
|
<endpoint method='post' path='/users'>
|
|
2369
3193
|
<body>
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
3194
|
+
<object
|
|
3195
|
+
description='The object of a user'
|
|
3196
|
+
/>
|
|
2373
3197
|
</body>
|
|
2374
3198
|
</endpoint>
|
|
2375
3199
|
</api>
|
|
@@ -2383,162 +3207,69 @@ export default (
|
|
|
2383
3207
|
|
|
2384
3208
|
The element MUST be placed inside [\<object>](#object).
|
|
2385
3209
|
It defines a `field` of an `object` value for a parent element.
|
|
2386
|
-
`@innet/server` formats and validate the value automatically (real-time).
|
|
2387
|
-
|
|
2388
|
-
`key` is REQUIRED prop of `<field>`, it defines a field name of the `<object>`.
|
|
2389
|
-
|
|
2390
|
-
*src/app.tsx*
|
|
2391
|
-
```typescript jsx
|
|
2392
|
-
export default (
|
|
2393
|
-
<server>
|
|
2394
|
-
<api>
|
|
2395
|
-
<endpoint method='post' path='/users'>
|
|
2396
|
-
<body>
|
|
2397
|
-
<object>
|
|
2398
|
-
<field key='name' />
|
|
2399
|
-
<field key='surname' />
|
|
2400
|
-
<field key='birthbay' />
|
|
2401
|
-
</object>
|
|
2402
|
-
</body>
|
|
2403
|
-
</endpoint>
|
|
2404
|
-
</api>
|
|
2405
|
-
</server>
|
|
2406
|
-
)
|
|
2407
|
-
```
|
|
2408
|
-
|
|
2409
|
-
#### optional
|
|
2410
|
-
|
|
2411
|
-
By default, any field is required. You can set it as `optional` by this prop.
|
|
2412
|
-
|
|
2413
|
-
*src/app.tsx*
|
|
2414
|
-
```typescript jsx
|
|
2415
|
-
export default (
|
|
2416
|
-
<server>
|
|
2417
|
-
<api>
|
|
2418
|
-
<endpoint method='post' path='/users'>
|
|
2419
|
-
<body>
|
|
2420
|
-
<object>
|
|
2421
|
-
<field key='name' />
|
|
2422
|
-
<field key='surname' />
|
|
2423
|
-
<field optional key='birthbay' />
|
|
2424
|
-
</object>
|
|
2425
|
-
</body>
|
|
2426
|
-
</endpoint>
|
|
2427
|
-
</api>
|
|
2428
|
-
</server>
|
|
2429
|
-
)
|
|
2430
|
-
```
|
|
2431
|
-
|
|
2432
|
-
## Run-Time
|
|
2433
|
-
|
|
2434
|
-
Next elements relate to run-time action.
|
|
2435
|
-
This action calls on user request.
|
|
2436
|
-
|
|
2437
|
-
[← back](#index)
|
|
2438
|
-
|
|
2439
|
-
Parent
|
|
2440
|
-
[\<fallback>](#fallback)
|
|
2441
|
-
[\<request>](#request)
|
|
2442
|
-
|
|
2443
|
-
Children
|
|
2444
|
-
[\<success>](#success)
|
|
2445
|
-
[\<error>](#error)
|
|
2446
|
-
[\<proxy>](#proxy)
|
|
2447
|
-
[\<redirect>](#redirect)
|
|
2448
|
-
[\<cms>](#cms)
|
|
2449
|
-
[\<file>](#file)
|
|
2450
|
-
[\<header>](#header)
|
|
2451
|
-
[\<cookie>](#cookie)
|
|
2452
|
-
|
|
2453
|
-
---
|
|
2454
|
-
|
|
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)
|
|
3210
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
2493
3211
|
|
|
2494
|
-
|
|
2495
|
-
It defines run-time call handler for the endpoint.
|
|
3212
|
+
`key` is REQUIRED prop of `<field>`, it defines a field name of the [\<object>](#object).
|
|
2496
3213
|
|
|
2497
3214
|
*src/app.tsx*
|
|
2498
3215
|
```typescript jsx
|
|
2499
3216
|
export default (
|
|
2500
3217
|
<server>
|
|
2501
3218
|
<api>
|
|
2502
|
-
<endpoint method='
|
|
2503
|
-
<
|
|
2504
|
-
<
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
3219
|
+
<endpoint method='post' path='/users'>
|
|
3220
|
+
<body>
|
|
3221
|
+
<object>
|
|
3222
|
+
<field key='name' />
|
|
3223
|
+
<field key='surname' />
|
|
3224
|
+
<field key='birthbay' />
|
|
3225
|
+
</object>
|
|
3226
|
+
</body>
|
|
2508
3227
|
</endpoint>
|
|
2509
3228
|
</api>
|
|
2510
3229
|
</server>
|
|
2511
3230
|
)
|
|
2512
3231
|
```
|
|
2513
3232
|
|
|
2514
|
-
|
|
2515
|
-
|
|
3233
|
+
#### optional
|
|
3234
|
+
|
|
3235
|
+
By default, any field is required. You can set it as `optional` by this prop.
|
|
2516
3236
|
|
|
2517
3237
|
*src/app.tsx*
|
|
2518
3238
|
```typescript jsx
|
|
2519
|
-
import { GetPartners } from './GetPartners'
|
|
2520
|
-
|
|
2521
3239
|
export default (
|
|
2522
3240
|
<server>
|
|
2523
3241
|
<api>
|
|
2524
|
-
<endpoint method='
|
|
2525
|
-
<
|
|
2526
|
-
|
|
2527
|
-
|
|
3242
|
+
<endpoint method='post' path='/users'>
|
|
3243
|
+
<body>
|
|
3244
|
+
<object>
|
|
3245
|
+
<field key='name' />
|
|
3246
|
+
<field key='surname' />
|
|
3247
|
+
<field optional key='birthbay' />
|
|
3248
|
+
</object>
|
|
3249
|
+
</body>
|
|
2528
3250
|
</endpoint>
|
|
2529
3251
|
</api>
|
|
2530
3252
|
</server>
|
|
2531
3253
|
)
|
|
2532
3254
|
```
|
|
2533
3255
|
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
3256
|
+
## Run-Time
|
|
3257
|
+
|
|
3258
|
+
Next elements relate to run-time action.
|
|
3259
|
+
This action calls on user request.
|
|
3260
|
+
|
|
3261
|
+
[← back](#index)
|
|
3262
|
+
|
|
3263
|
+
[\<success>](#success)
|
|
3264
|
+
[\<error>](#error)
|
|
3265
|
+
[\<proxy>](#proxy)
|
|
3266
|
+
[\<redirect>](#redirect)
|
|
3267
|
+
[\<cms>](#cms)
|
|
3268
|
+
[\<file>](#file)
|
|
3269
|
+
[\<header>](#header)
|
|
3270
|
+
[\<cookie>](#cookie)
|
|
3271
|
+
|
|
3272
|
+
---
|
|
2542
3273
|
|
|
2543
3274
|
### \<success>
|
|
2544
3275
|
|
|
@@ -2550,11 +3281,9 @@ This is a base element to return a success data.
|
|
|
2550
3281
|
```typescript jsx
|
|
2551
3282
|
export default (
|
|
2552
3283
|
<server>
|
|
2553
|
-
<
|
|
2554
|
-
<
|
|
2555
|
-
|
|
2556
|
-
</fallback>
|
|
2557
|
-
</api>
|
|
3284
|
+
<response>
|
|
3285
|
+
<success />
|
|
3286
|
+
</response>
|
|
2558
3287
|
</server>
|
|
2559
3288
|
)
|
|
2560
3289
|
```
|
|
@@ -2569,13 +3298,11 @@ const data = {...}
|
|
|
2569
3298
|
|
|
2570
3299
|
export default (
|
|
2571
3300
|
<server>
|
|
2572
|
-
<
|
|
2573
|
-
<
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
</fallback>
|
|
2578
|
-
</api>
|
|
3301
|
+
<response>
|
|
3302
|
+
<success>
|
|
3303
|
+
{data}
|
|
3304
|
+
</success>
|
|
3305
|
+
</response>
|
|
2579
3306
|
</server>
|
|
2580
3307
|
)
|
|
2581
3308
|
```
|
|
@@ -2592,13 +3319,11 @@ const data = {...}
|
|
|
2592
3319
|
|
|
2593
3320
|
export default (
|
|
2594
3321
|
<server>
|
|
2595
|
-
<
|
|
2596
|
-
<
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
</fallback>
|
|
2601
|
-
</api>
|
|
3322
|
+
<response>
|
|
3323
|
+
<success status='created'>
|
|
3324
|
+
{data}
|
|
3325
|
+
</success>
|
|
3326
|
+
</response>
|
|
2602
3327
|
</server>
|
|
2603
3328
|
)
|
|
2604
3329
|
```
|
|
@@ -2613,13 +3338,29 @@ const data = {...}
|
|
|
2613
3338
|
|
|
2614
3339
|
export default (
|
|
2615
3340
|
<server>
|
|
2616
|
-
<
|
|
2617
|
-
<
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
3341
|
+
<response>
|
|
3342
|
+
<success status={201}>
|
|
3343
|
+
{data}
|
|
3344
|
+
</success>
|
|
3345
|
+
</response>
|
|
3346
|
+
</server>
|
|
3347
|
+
)
|
|
3348
|
+
```
|
|
3349
|
+
|
|
3350
|
+
#### contentType
|
|
3351
|
+
|
|
3352
|
+
This props sets response content type.
|
|
3353
|
+
By default, it checks children element to define the prop.
|
|
3354
|
+
|
|
3355
|
+
*src/app.tsx*
|
|
3356
|
+
```typescript jsx
|
|
3357
|
+
export default (
|
|
3358
|
+
<server>
|
|
3359
|
+
<response>
|
|
3360
|
+
<success contentType='text/html'>
|
|
3361
|
+
Hello World!
|
|
3362
|
+
</success>
|
|
3363
|
+
</response>
|
|
2623
3364
|
</server>
|
|
2624
3365
|
)
|
|
2625
3366
|
```
|
|
@@ -2629,17 +3370,15 @@ export default (
|
|
|
2629
3370
|
[← back](#run-time)
|
|
2630
3371
|
|
|
2631
3372
|
Returns an error.
|
|
2632
|
-
This element MUST be placed in [\<
|
|
3373
|
+
This element MUST be placed in [\<return>](#return) or [\<response>](#response).
|
|
2633
3374
|
|
|
2634
3375
|
*src/app.tsx*
|
|
2635
3376
|
```typescript jsx
|
|
2636
3377
|
export default (
|
|
2637
3378
|
<server>
|
|
2638
|
-
<
|
|
2639
|
-
<
|
|
2640
|
-
|
|
2641
|
-
</fallback>
|
|
2642
|
-
</api>
|
|
3379
|
+
<response>
|
|
3380
|
+
<error />
|
|
3381
|
+
</response>
|
|
2643
3382
|
</server>
|
|
2644
3383
|
)
|
|
2645
3384
|
```
|
|
@@ -2652,13 +3391,11 @@ const data = {...}
|
|
|
2652
3391
|
|
|
2653
3392
|
export default (
|
|
2654
3393
|
<server>
|
|
2655
|
-
<
|
|
2656
|
-
<
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
</fallback>
|
|
2661
|
-
</api>
|
|
3394
|
+
<response>
|
|
3395
|
+
<error>
|
|
3396
|
+
{data}
|
|
3397
|
+
</error>
|
|
3398
|
+
</response>
|
|
2662
3399
|
</server>
|
|
2663
3400
|
)
|
|
2664
3401
|
```
|
|
@@ -2674,13 +3411,11 @@ const data = {
|
|
|
2674
3411
|
|
|
2675
3412
|
export default (
|
|
2676
3413
|
<server>
|
|
2677
|
-
<
|
|
2678
|
-
<
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
</fallback>
|
|
2683
|
-
</api>
|
|
3414
|
+
<response>
|
|
3415
|
+
<error status='notFound'>
|
|
3416
|
+
{data}
|
|
3417
|
+
</error>
|
|
3418
|
+
</response>
|
|
2684
3419
|
</server>
|
|
2685
3420
|
)
|
|
2686
3421
|
```
|
|
@@ -2695,13 +3430,11 @@ const data = {
|
|
|
2695
3430
|
|
|
2696
3431
|
export default (
|
|
2697
3432
|
<server>
|
|
2698
|
-
<
|
|
2699
|
-
<
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
</fallback>
|
|
2704
|
-
</api>
|
|
3433
|
+
<response>
|
|
3434
|
+
<error status={404}>
|
|
3435
|
+
{data}
|
|
3436
|
+
</error>
|
|
3437
|
+
</response>
|
|
2705
3438
|
</server>
|
|
2706
3439
|
)
|
|
2707
3440
|
```
|
|
@@ -2729,15 +3462,13 @@ const data = {
|
|
|
2729
3462
|
|
|
2730
3463
|
export default (
|
|
2731
3464
|
<server>
|
|
2732
|
-
<
|
|
2733
|
-
<
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
</fallback>
|
|
2740
|
-
</api>
|
|
3465
|
+
<response>
|
|
3466
|
+
<error
|
|
3467
|
+
code='noUser'
|
|
3468
|
+
status='notFound'>
|
|
3469
|
+
{data}
|
|
3470
|
+
</error>
|
|
3471
|
+
</response>
|
|
2741
3472
|
</server>
|
|
2742
3473
|
)
|
|
2743
3474
|
```
|
|
@@ -2765,7 +3496,7 @@ There are some default errors:
|
|
|
2765
3496
|
|
|
2766
3497
|
[← back](#run-time)
|
|
2767
3498
|
|
|
2768
|
-
MUST be placed in [\<
|
|
3499
|
+
MUST be placed in [\<return>](#return) or [\<response>](#response).
|
|
2769
3500
|
|
|
2770
3501
|
You can easy proxy endpoints to another server/service.
|
|
2771
3502
|
|
|
@@ -2777,14 +3508,14 @@ export default (
|
|
|
2777
3508
|
<endpoint
|
|
2778
3509
|
path='/test'
|
|
2779
3510
|
method='get'>
|
|
2780
|
-
<
|
|
3511
|
+
<return>
|
|
2781
3512
|
<proxy to='https://...' />
|
|
2782
|
-
</
|
|
3513
|
+
</return>
|
|
2783
3514
|
</endpoint>
|
|
2784
|
-
<fallback>
|
|
2785
|
-
<proxy to='https://...' />
|
|
2786
|
-
</fallback>
|
|
2787
3515
|
</api>
|
|
3516
|
+
<response>
|
|
3517
|
+
<proxy to='https://...' />
|
|
3518
|
+
</response>
|
|
2788
3519
|
</server>
|
|
2789
3520
|
)
|
|
2790
3521
|
```
|
|
@@ -2793,7 +3524,7 @@ export default (
|
|
|
2793
3524
|
|
|
2794
3525
|
[← back](#run-time)
|
|
2795
3526
|
|
|
2796
|
-
MUST be placed in [\<
|
|
3527
|
+
MUST be placed in [\<return>](#return) or [\<response>](#response).
|
|
2797
3528
|
|
|
2798
3529
|
You can redirect users to another resource. It adds `Cache-Control` header by default.
|
|
2799
3530
|
|
|
@@ -2805,14 +3536,14 @@ export default (
|
|
|
2805
3536
|
<endpoint
|
|
2806
3537
|
path='/test'
|
|
2807
3538
|
method='get'>
|
|
2808
|
-
<
|
|
3539
|
+
<return>
|
|
2809
3540
|
<redirect to='https://...' />
|
|
2810
|
-
</
|
|
3541
|
+
</return>
|
|
2811
3542
|
</endpoint>
|
|
2812
|
-
<fallback>
|
|
2813
|
-
<redirect to='https://...' />
|
|
2814
|
-
</fallback>
|
|
2815
3543
|
</api>
|
|
3544
|
+
<return>
|
|
3545
|
+
<redirect to='https://...' />
|
|
3546
|
+
</return>
|
|
2816
3547
|
</server>
|
|
2817
3548
|
)
|
|
2818
3549
|
```
|
|
@@ -2830,20 +3561,20 @@ export default (
|
|
|
2830
3561
|
<endpoint
|
|
2831
3562
|
path='/test'
|
|
2832
3563
|
method='get'>
|
|
2833
|
-
<
|
|
3564
|
+
<return>
|
|
2834
3565
|
<redirect
|
|
2835
3566
|
status='found'
|
|
2836
3567
|
to='https://...'
|
|
2837
3568
|
/>
|
|
2838
|
-
</
|
|
3569
|
+
</return>
|
|
2839
3570
|
</endpoint>
|
|
2840
|
-
<fallback>
|
|
2841
|
-
<redirect
|
|
2842
|
-
status={303}
|
|
2843
|
-
to='https://...'
|
|
2844
|
-
/>
|
|
2845
|
-
</fallback>
|
|
2846
3571
|
</api>
|
|
3572
|
+
<response>
|
|
3573
|
+
<redirect
|
|
3574
|
+
status={303}
|
|
3575
|
+
to='https://...'
|
|
3576
|
+
/>
|
|
3577
|
+
</response>
|
|
2847
3578
|
</server>
|
|
2848
3579
|
)
|
|
2849
3580
|
```
|
|
@@ -2852,7 +3583,7 @@ export default (
|
|
|
2852
3583
|
|
|
2853
3584
|
[← back](#run-time)
|
|
2854
3585
|
|
|
2855
|
-
MUST be placed in [\<
|
|
3586
|
+
MUST be placed in [\<return>](#return) or [\<response>](#response).
|
|
2856
3587
|
|
|
2857
3588
|
`<cms>` helps to return files from a folder by path. It checks files run-time on the server.
|
|
2858
3589
|
|
|
@@ -2860,18 +3591,16 @@ MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
|
2860
3591
|
```typescript jsx
|
|
2861
3592
|
export default (
|
|
2862
3593
|
<server>
|
|
2863
|
-
<
|
|
2864
|
-
<
|
|
2865
|
-
|
|
2866
|
-
</fallback>
|
|
2867
|
-
</api>
|
|
3594
|
+
<response>
|
|
3595
|
+
<cms />
|
|
3596
|
+
</response>
|
|
2868
3597
|
</server>
|
|
2869
3598
|
)
|
|
2870
3599
|
```
|
|
2871
3600
|
|
|
2872
3601
|
#### dir
|
|
2873
3602
|
|
|
2874
|
-
By default, it
|
|
3603
|
+
By default, it equals `INNET_CMS_DIR` node env variable or the project folder.
|
|
2875
3604
|
If you try the previous example on [http://localhost/package.json](http://localhost/package.json)
|
|
2876
3605
|
you get the project `package.json` file.
|
|
2877
3606
|
|
|
@@ -2881,11 +3610,9 @@ You can change root folder by `dir` property.
|
|
|
2881
3610
|
```typescript jsx
|
|
2882
3611
|
export default (
|
|
2883
3612
|
<server>
|
|
2884
|
-
<
|
|
2885
|
-
<
|
|
2886
|
-
|
|
2887
|
-
</fallback>
|
|
2888
|
-
</api>
|
|
3613
|
+
<response>
|
|
3614
|
+
<cms dir='src' />
|
|
3615
|
+
</response>
|
|
2889
3616
|
</server>
|
|
2890
3617
|
)
|
|
2891
3618
|
```
|
|
@@ -2896,15 +3623,16 @@ you get the index file in `src` folder.
|
|
|
2896
3623
|
#### prefix
|
|
2897
3624
|
|
|
2898
3625
|
`<cms>` matches full `path`, you should take it into account if you add `prefix` on `<api>`.
|
|
3626
|
+
By default, it equals `INNET_CMS_PREFIX` node env variable or `/`.
|
|
2899
3627
|
|
|
2900
3628
|
*src/app.tsx*
|
|
2901
3629
|
```typescript jsx
|
|
2902
3630
|
export default (
|
|
2903
3631
|
<server>
|
|
2904
3632
|
<api prefix='/src'>
|
|
2905
|
-
<
|
|
3633
|
+
<response>
|
|
2906
3634
|
<cms />
|
|
2907
|
-
</
|
|
3635
|
+
</response>
|
|
2908
3636
|
</api>
|
|
2909
3637
|
</server>
|
|
2910
3638
|
)
|
|
@@ -2920,9 +3648,9 @@ You can reduce the path for matching by prefix property of `<cms>`.
|
|
|
2920
3648
|
export default (
|
|
2921
3649
|
<server>
|
|
2922
3650
|
<api prefix='/api'>
|
|
2923
|
-
<
|
|
3651
|
+
<response>
|
|
2924
3652
|
<cms prefix='/api' />
|
|
2925
|
-
</
|
|
3653
|
+
</response>
|
|
2926
3654
|
</api>
|
|
2927
3655
|
</server>
|
|
2928
3656
|
)
|
|
@@ -2938,13 +3666,11 @@ You can handle if a file was not found by children elements of `<cms>`.
|
|
|
2938
3666
|
```typescript jsx
|
|
2939
3667
|
export default (
|
|
2940
3668
|
<server>
|
|
2941
|
-
<
|
|
2942
|
-
<
|
|
2943
|
-
<
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
</fallback>
|
|
2947
|
-
</api>
|
|
3669
|
+
<response>
|
|
3670
|
+
<cms>
|
|
3671
|
+
<error status={404} />
|
|
3672
|
+
</cms>
|
|
3673
|
+
</response>
|
|
2948
3674
|
</server>
|
|
2949
3675
|
)
|
|
2950
3676
|
```
|
|
@@ -2953,7 +3679,7 @@ export default (
|
|
|
2953
3679
|
|
|
2954
3680
|
[← back](#run-time)
|
|
2955
3681
|
|
|
2956
|
-
It returns a file. MUST be placed in [\<
|
|
3682
|
+
It returns a file. MUST be placed in [\<return>](#return) or [\<response>](#response).
|
|
2957
3683
|
|
|
2958
3684
|
It adds `Content-Length` and `Content-Type` automatically.
|
|
2959
3685
|
|
|
@@ -2963,13 +3689,9 @@ It has a REQUIRED property of `path`.
|
|
|
2963
3689
|
```typescript jsx
|
|
2964
3690
|
export default (
|
|
2965
3691
|
<server>
|
|
2966
|
-
<
|
|
2967
|
-
<
|
|
2968
|
-
|
|
2969
|
-
path='package.json'
|
|
2970
|
-
/>
|
|
2971
|
-
</fallback>
|
|
2972
|
-
</api>
|
|
3692
|
+
<response>
|
|
3693
|
+
<file path='package.json' />
|
|
3694
|
+
</response>
|
|
2973
3695
|
</server>
|
|
2974
3696
|
)
|
|
2975
3697
|
```
|
|
@@ -2984,20 +3706,18 @@ You can handle if a file was not found by children elements of `<file>`.
|
|
|
2984
3706
|
```typescript jsx
|
|
2985
3707
|
export default (
|
|
2986
3708
|
<server>
|
|
2987
|
-
<
|
|
2988
|
-
<
|
|
2989
|
-
<
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
</fallback>
|
|
2993
|
-
</api>
|
|
3709
|
+
<response>
|
|
3710
|
+
<file path='file_is_not_exist.txt'>
|
|
3711
|
+
<error status={404} />
|
|
3712
|
+
</file>
|
|
3713
|
+
</response>
|
|
2994
3714
|
</server>
|
|
2995
3715
|
)
|
|
2996
3716
|
```
|
|
2997
3717
|
|
|
2998
3718
|
### \<header>
|
|
2999
3719
|
|
|
3000
|
-
MUST be placed in [\<
|
|
3720
|
+
MUST be placed in [\<return>](#return) or [\<response>](#response).
|
|
3001
3721
|
|
|
3002
3722
|
[← back](#run-time)
|
|
3003
3723
|
|
|
@@ -3007,22 +3727,20 @@ You can add an HTTP header into response by `<header>` element.
|
|
|
3007
3727
|
```typescript jsx
|
|
3008
3728
|
export default (
|
|
3009
3729
|
<server>
|
|
3010
|
-
<
|
|
3011
|
-
<
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
</fallback>
|
|
3018
|
-
</api>
|
|
3730
|
+
<response>
|
|
3731
|
+
<header
|
|
3732
|
+
key='Cache-Control'
|
|
3733
|
+
value='no-cache, no-store, must-revalidate'
|
|
3734
|
+
/>
|
|
3735
|
+
<success />
|
|
3736
|
+
</response>
|
|
3019
3737
|
</server>
|
|
3020
3738
|
)
|
|
3021
3739
|
```
|
|
3022
3740
|
|
|
3023
3741
|
### \<cookie>
|
|
3024
3742
|
|
|
3025
|
-
MUST be placed in [\<
|
|
3743
|
+
MUST be placed in [\<return>](#return) or [\<response>](#response).
|
|
3026
3744
|
|
|
3027
3745
|
[← back](#run-time)
|
|
3028
3746
|
|
|
@@ -3032,18 +3750,16 @@ You can add/remove a cookie into response by `<cookie>` element.
|
|
|
3032
3750
|
```typescript jsx
|
|
3033
3751
|
export default (
|
|
3034
3752
|
<server>
|
|
3035
|
-
<
|
|
3036
|
-
<
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
</fallback>
|
|
3046
|
-
</api>
|
|
3753
|
+
<response>
|
|
3754
|
+
<cookie
|
|
3755
|
+
key='token'
|
|
3756
|
+
value='...'
|
|
3757
|
+
/>
|
|
3758
|
+
<cookie
|
|
3759
|
+
key='removedCookie'
|
|
3760
|
+
/>
|
|
3761
|
+
<success />
|
|
3762
|
+
</response>
|
|
3047
3763
|
</server>
|
|
3048
3764
|
)
|
|
3049
3765
|
```
|
|
@@ -3057,16 +3773,14 @@ By default, no domain is set, and most clients will consider the cookie to apply
|
|
|
3057
3773
|
```typescript jsx
|
|
3058
3774
|
export default (
|
|
3059
3775
|
<server>
|
|
3060
|
-
<
|
|
3061
|
-
<
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
</fallback>
|
|
3069
|
-
</api>
|
|
3776
|
+
<response>
|
|
3777
|
+
<cookie
|
|
3778
|
+
domain='.example.com'
|
|
3779
|
+
key='token'
|
|
3780
|
+
value='...'
|
|
3781
|
+
/>
|
|
3782
|
+
<success />
|
|
3783
|
+
</response>
|
|
3070
3784
|
</server>
|
|
3071
3785
|
)
|
|
3072
3786
|
```
|
|
@@ -3085,16 +3799,14 @@ Note the [cookie storage model specification](https://datatracker.ietf.org/doc/h
|
|
|
3085
3799
|
```typescript jsx
|
|
3086
3800
|
export default (
|
|
3087
3801
|
<server>
|
|
3088
|
-
<
|
|
3089
|
-
<
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
</fallback>
|
|
3097
|
-
</api>
|
|
3802
|
+
<response>
|
|
3803
|
+
<cookie
|
|
3804
|
+
expires={new Date('2050-01-01')}
|
|
3805
|
+
key='token'
|
|
3806
|
+
value='...'
|
|
3807
|
+
/>
|
|
3808
|
+
<success />
|
|
3809
|
+
</response>
|
|
3098
3810
|
</server>
|
|
3099
3811
|
)
|
|
3100
3812
|
```
|
|
@@ -3108,16 +3820,14 @@ Note be careful when setting this to true, as compliant clients will not allow c
|
|
|
3108
3820
|
```typescript jsx
|
|
3109
3821
|
export default (
|
|
3110
3822
|
<server>
|
|
3111
|
-
<
|
|
3112
|
-
<
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
</fallback>
|
|
3120
|
-
</api>
|
|
3823
|
+
<response>
|
|
3824
|
+
<cookie
|
|
3825
|
+
httpOnly
|
|
3826
|
+
key='token'
|
|
3827
|
+
value='...'
|
|
3828
|
+
/>
|
|
3829
|
+
<success />
|
|
3830
|
+
</response>
|
|
3121
3831
|
</server>
|
|
3122
3832
|
)
|
|
3123
3833
|
```
|
|
@@ -3131,17 +3841,15 @@ Note the [cookie storage model specification](https://datatracker.ietf.org/doc/h
|
|
|
3131
3841
|
```typescript jsx
|
|
3132
3842
|
export default (
|
|
3133
3843
|
<server>
|
|
3134
|
-
<
|
|
3135
|
-
<
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
</fallback>
|
|
3144
|
-
</api>
|
|
3844
|
+
<response>
|
|
3845
|
+
<cookie
|
|
3846
|
+
httpOnly
|
|
3847
|
+
maxAge={9999}
|
|
3848
|
+
key='token'
|
|
3849
|
+
value='...'
|
|
3850
|
+
/>
|
|
3851
|
+
<success />
|
|
3852
|
+
</response>
|
|
3145
3853
|
</server>
|
|
3146
3854
|
)
|
|
3147
3855
|
```
|
|
@@ -3155,18 +3863,16 @@ By default, the path is considered the “default path”.
|
|
|
3155
3863
|
```typescript jsx
|
|
3156
3864
|
export default (
|
|
3157
3865
|
<server>
|
|
3158
|
-
<
|
|
3159
|
-
<
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
</fallback>
|
|
3169
|
-
</api>
|
|
3866
|
+
<response>
|
|
3867
|
+
<cookie
|
|
3868
|
+
httpOnly
|
|
3869
|
+
maxAge={9999}
|
|
3870
|
+
path='/src'
|
|
3871
|
+
key='token'
|
|
3872
|
+
value='...'
|
|
3873
|
+
/>
|
|
3874
|
+
<success />
|
|
3875
|
+
</response>
|
|
3170
3876
|
</server>
|
|
3171
3877
|
)
|
|
3172
3878
|
```
|
|
@@ -3185,18 +3891,16 @@ note This is an attribute that has not yet been fully standardized, and may chan
|
|
|
3185
3891
|
```typescript jsx
|
|
3186
3892
|
export default (
|
|
3187
3893
|
<server>
|
|
3188
|
-
<
|
|
3189
|
-
<
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
</fallback>
|
|
3199
|
-
</api>
|
|
3894
|
+
<response>
|
|
3895
|
+
<cookie
|
|
3896
|
+
httpOnly
|
|
3897
|
+
priority='high'
|
|
3898
|
+
path='/src'
|
|
3899
|
+
key='token'
|
|
3900
|
+
value='...'
|
|
3901
|
+
/>
|
|
3902
|
+
<success />
|
|
3903
|
+
</response>
|
|
3200
3904
|
</server>
|
|
3201
3905
|
)
|
|
3202
3906
|
```
|
|
@@ -3218,19 +3922,17 @@ This also means many clients may ignore this attribute until they understand it.
|
|
|
3218
3922
|
```typescript jsx
|
|
3219
3923
|
export default (
|
|
3220
3924
|
<server>
|
|
3221
|
-
<
|
|
3222
|
-
<
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
</fallback>
|
|
3233
|
-
</api>
|
|
3925
|
+
<response>
|
|
3926
|
+
<cookie
|
|
3927
|
+
httpOnly
|
|
3928
|
+
sameSite
|
|
3929
|
+
priority='high'
|
|
3930
|
+
path='/src'
|
|
3931
|
+
key='token'
|
|
3932
|
+
value='...'
|
|
3933
|
+
/>
|
|
3934
|
+
<success />
|
|
3935
|
+
</response>
|
|
3234
3936
|
</server>
|
|
3235
3937
|
)
|
|
3236
3938
|
```
|
|
@@ -3247,17 +3949,15 @@ Note be careful when setting this to true, as compliant clients will not send th
|
|
|
3247
3949
|
```typescript jsx
|
|
3248
3950
|
export default (
|
|
3249
3951
|
<server>
|
|
3250
|
-
<
|
|
3251
|
-
<
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
</fallback>
|
|
3260
|
-
</api>
|
|
3952
|
+
<response>
|
|
3953
|
+
<cookie
|
|
3954
|
+
httpOnly
|
|
3955
|
+
secure
|
|
3956
|
+
key='token'
|
|
3957
|
+
value='...'
|
|
3958
|
+
/>
|
|
3959
|
+
<success />
|
|
3960
|
+
</response>
|
|
3261
3961
|
</server>
|
|
3262
3962
|
)
|
|
3263
3963
|
```
|
|
@@ -3290,14 +3990,12 @@ import { SetToken } from './SetToken'
|
|
|
3290
3990
|
|
|
3291
3991
|
export default (
|
|
3292
3992
|
<server>
|
|
3293
|
-
<
|
|
3294
|
-
<
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
</fallback>
|
|
3300
|
-
</api>
|
|
3993
|
+
<response>
|
|
3994
|
+
<SetToken
|
|
3995
|
+
value='...'
|
|
3996
|
+
/>
|
|
3997
|
+
<success />
|
|
3998
|
+
</response>
|
|
3301
3999
|
</server>
|
|
3302
4000
|
)
|
|
3303
4001
|
```
|
|
@@ -3310,7 +4008,7 @@ Hook functions give you all features to control parent element functionality.
|
|
|
3310
4008
|
|
|
3311
4009
|
[← back](#index)
|
|
3312
4010
|
|
|
3313
|
-
|
|
4011
|
+
Real-time
|
|
3314
4012
|
[useRequest](#userequest)
|
|
3315
4013
|
[useResponse](#useresponse)
|
|
3316
4014
|
[useHeaders](#useheaders)
|
|
@@ -3319,35 +4017,24 @@ Hook functions give you all features to control parent element functionality.
|
|
|
3319
4017
|
[useParams](#useparams)
|
|
3320
4018
|
[useSearch](#usesearch)
|
|
3321
4019
|
[useBody](#usebody)
|
|
4020
|
+
[useClientIp](#useclientip)
|
|
3322
4021
|
|
|
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()
|
|
4022
|
+
Server start
|
|
4023
|
+
[useServerPlugin](#useserverplugin)
|
|
3339
4024
|
|
|
3340
|
-
|
|
4025
|
+
Both
|
|
4026
|
+
[useServer](#useserver)
|
|
4027
|
+
[usePort](#useport)
|
|
4028
|
+
[useIsServerHttps](#useisserverhttps)
|
|
4029
|
+
[useComponentName](#usecomponentname)
|
|
3341
4030
|
|
|
3342
|
-
|
|
3343
|
-
}
|
|
3344
|
-
```
|
|
4031
|
+
---
|
|
3345
4032
|
|
|
3346
4033
|
### useRequest
|
|
3347
4034
|
|
|
3348
4035
|
[← back](#hooks)
|
|
3349
4036
|
|
|
3350
|
-
This hook MUST be used in a component placed in [\<
|
|
4037
|
+
This hook MUST be used in a component placed in [\<return>](#return) or [\<response>](#response).
|
|
3351
4038
|
This hook returns current request instance.
|
|
3352
4039
|
|
|
3353
4040
|
*src/Component.tsx*
|
|
@@ -3368,7 +4055,7 @@ export function Component () {
|
|
|
3368
4055
|
|
|
3369
4056
|
[← back](#hooks)
|
|
3370
4057
|
|
|
3371
|
-
This hook MUST be used in a component placed in [\<
|
|
4058
|
+
This hook MUST be used in a component placed in [\<return>](#return) or [\<response>](#response).
|
|
3372
4059
|
This hook returns current response instance.
|
|
3373
4060
|
|
|
3374
4061
|
*src/Component.tsx*
|
|
@@ -3389,7 +4076,7 @@ export function Component () {
|
|
|
3389
4076
|
|
|
3390
4077
|
[← back](#hooks)
|
|
3391
4078
|
|
|
3392
|
-
This hook MUST be used in a component placed in [\<
|
|
4079
|
+
This hook MUST be used in a component placed in [\<return>](#return) or [\<response>](#response).
|
|
3393
4080
|
This hook returns current request headers object.
|
|
3394
4081
|
|
|
3395
4082
|
*src/Component.tsx*
|
|
@@ -3408,7 +4095,7 @@ export function Component () {
|
|
|
3408
4095
|
|
|
3409
4096
|
[← back](#hooks)
|
|
3410
4097
|
|
|
3411
|
-
This hook MUST be used in a component placed in [\<
|
|
4098
|
+
This hook MUST be used in a component placed in [\<return>](#return) or [\<response>](#response).
|
|
3412
4099
|
This hook returns current request cookies object.
|
|
3413
4100
|
|
|
3414
4101
|
*src/Component.tsx*
|
|
@@ -3427,7 +4114,7 @@ export function Component () {
|
|
|
3427
4114
|
|
|
3428
4115
|
[← back](#hooks)
|
|
3429
4116
|
|
|
3430
|
-
This hook MUST be used in a component placed in [\<
|
|
4117
|
+
This hook MUST be used in a component placed in [\<return>](#return) or [\<response>](#response).
|
|
3431
4118
|
This hook returns current request URL path as a `string`.
|
|
3432
4119
|
|
|
3433
4120
|
*src/Component.tsx*
|
|
@@ -3446,7 +4133,7 @@ export function Component () {
|
|
|
3446
4133
|
|
|
3447
4134
|
[← back](#hooks)
|
|
3448
4135
|
|
|
3449
|
-
This hook MUST be used in a component placed in [\<
|
|
4136
|
+
This hook MUST be used in a component placed in [\<return>](#return) or [\<response>](#response).
|
|
3450
4137
|
This hook returns an object of URL params you set by [\<param>](#param).
|
|
3451
4138
|
|
|
3452
4139
|
*src/Component.tsx*
|
|
@@ -3464,7 +4151,7 @@ export function Component () {
|
|
|
3464
4151
|
|
|
3465
4152
|
[← back](#hooks)
|
|
3466
4153
|
|
|
3467
|
-
This hook MUST be used in a component placed in [\<
|
|
4154
|
+
This hook MUST be used in a component placed in [\<return>](#return) or [\<response>](#response).
|
|
3468
4155
|
This hook returns an object of URL query params.
|
|
3469
4156
|
|
|
3470
4157
|
*src/Component.tsx*
|
|
@@ -3482,7 +4169,7 @@ export function Component () {
|
|
|
3482
4169
|
|
|
3483
4170
|
[← back](#hooks)
|
|
3484
4171
|
|
|
3485
|
-
This hook MUST be used in a component placed in [\<
|
|
4172
|
+
This hook MUST be used in a component placed in [\<return>](#return) or [\<response>](#response).
|
|
3486
4173
|
This hook returns current request body.
|
|
3487
4174
|
|
|
3488
4175
|
*src/Component.tsx*
|
|
@@ -3496,6 +4183,153 @@ export function Component () {
|
|
|
3496
4183
|
}
|
|
3497
4184
|
```
|
|
3498
4185
|
|
|
4186
|
+
### useClientIp
|
|
4187
|
+
|
|
4188
|
+
[← back](#hooks)
|
|
4189
|
+
|
|
4190
|
+
This hook returns request user IP.
|
|
4191
|
+
This hook MUST be used in a component placed in [\<return>](#return) or [\<response>](#response).
|
|
4192
|
+
|
|
4193
|
+
*src/Component.tsx*
|
|
4194
|
+
```typescript jsx
|
|
4195
|
+
import { useClientIp } from '@innet/sever'
|
|
4196
|
+
|
|
4197
|
+
export function Component () {
|
|
4198
|
+
const ip = useClientIp()
|
|
4199
|
+
|
|
4200
|
+
return <success>{{ ip }}</success>
|
|
4201
|
+
}
|
|
4202
|
+
```
|
|
4203
|
+
|
|
4204
|
+
### useServerPlugin
|
|
4205
|
+
|
|
4206
|
+
[← back](#hooks)
|
|
4207
|
+
|
|
4208
|
+
This hook adds a request plugin function.
|
|
4209
|
+
The function runs before check endpoints.
|
|
4210
|
+
If the function returns `true` the request handling stops, and you get full control over the request.
|
|
4211
|
+
|
|
4212
|
+
This hook MUST be used in a component placed in [\<server>](#server).
|
|
4213
|
+
|
|
4214
|
+
*src/SecretEndpoint.tsx*
|
|
4215
|
+
```typescript jsx
|
|
4216
|
+
import { useRequestPlugin, useAction } from '@innet/sever'
|
|
4217
|
+
|
|
4218
|
+
export function SecretEndpoint () {
|
|
4219
|
+
useServerPlugin(() => {
|
|
4220
|
+
const action = useAction()
|
|
4221
|
+
|
|
4222
|
+
if (action.path.startsWith('/secret-endpoint')) {
|
|
4223
|
+
return <success>A secret message</success>
|
|
4224
|
+
}
|
|
4225
|
+
})
|
|
4226
|
+
}
|
|
4227
|
+
```
|
|
4228
|
+
|
|
4229
|
+
Then use the plugin in [\<server>](#server) or [\<api>](#api).
|
|
4230
|
+
|
|
4231
|
+
*src/app.tsx*
|
|
4232
|
+
```typescript jsx
|
|
4233
|
+
import { SecretEndpoint } from './SecretEndpoint'
|
|
4234
|
+
|
|
4235
|
+
export default (
|
|
4236
|
+
<server>
|
|
4237
|
+
<SecretEndpoint />
|
|
4238
|
+
<response>
|
|
4239
|
+
<error />
|
|
4240
|
+
</response>
|
|
4241
|
+
</server>
|
|
4242
|
+
)
|
|
4243
|
+
```
|
|
4244
|
+
|
|
4245
|
+
Any endpoint returns an error except for `/secret-endpoint`.
|
|
4246
|
+
Elements order does not matter.
|
|
4247
|
+
|
|
4248
|
+
### useServer
|
|
4249
|
+
|
|
4250
|
+
[← back](#hooks)
|
|
4251
|
+
|
|
4252
|
+
This hook MUST be used in a component placed in [\<server>](#server).
|
|
4253
|
+
This hook returns current http(s) server instance.
|
|
4254
|
+
|
|
4255
|
+
*src/Component.tsx*
|
|
4256
|
+
```typescript jsx
|
|
4257
|
+
import { useServer } from '@innet/sever'
|
|
4258
|
+
|
|
4259
|
+
export function Component () {
|
|
4260
|
+
const server = useServer()
|
|
4261
|
+
|
|
4262
|
+
console.log(server)
|
|
4263
|
+
|
|
4264
|
+
return <success />
|
|
4265
|
+
}
|
|
4266
|
+
```
|
|
4267
|
+
|
|
4268
|
+
### usePort
|
|
4269
|
+
|
|
4270
|
+
[← back](#hooks)
|
|
4271
|
+
|
|
4272
|
+
This hook MUST be used in a component placed in [\<server>](#server).
|
|
4273
|
+
This hook returns current http(s) server port.
|
|
4274
|
+
|
|
4275
|
+
*src/LocalHost.tsx*
|
|
4276
|
+
```typescript jsx
|
|
4277
|
+
import { usePort } from '@innet/sever'
|
|
4278
|
+
|
|
4279
|
+
export function LocalHost () {
|
|
4280
|
+
const port = usePort()
|
|
4281
|
+
|
|
4282
|
+
return (
|
|
4283
|
+
<host
|
|
4284
|
+
description='Development'
|
|
4285
|
+
url={`http://localhost:${port}/api`}
|
|
4286
|
+
/>
|
|
4287
|
+
)
|
|
4288
|
+
}
|
|
4289
|
+
```
|
|
4290
|
+
|
|
4291
|
+
### useIsServerHttps
|
|
4292
|
+
|
|
4293
|
+
[← back](#hooks)
|
|
4294
|
+
|
|
4295
|
+
This hook MUST be used in a component placed in [\<server>](#server).
|
|
4296
|
+
This hook returns `true` if it is https server and `false` if not.
|
|
4297
|
+
|
|
4298
|
+
*src/LocalHost.tsx*
|
|
4299
|
+
```typescript jsx
|
|
4300
|
+
import { usePort, useIsServerHttps } from '@innet/sever'
|
|
4301
|
+
|
|
4302
|
+
export function LocalHost () {
|
|
4303
|
+
const https = useIsServerHttps() ? 'https' : 'http'
|
|
4304
|
+
const port = usePort()
|
|
4305
|
+
|
|
4306
|
+
return (
|
|
4307
|
+
<host
|
|
4308
|
+
description='Development'
|
|
4309
|
+
url={`${https}://localhost:${port}/api`}
|
|
4310
|
+
/>
|
|
4311
|
+
)
|
|
4312
|
+
}
|
|
4313
|
+
```
|
|
4314
|
+
|
|
4315
|
+
### useComponentName
|
|
4316
|
+
|
|
4317
|
+
[← back](#hooks)
|
|
4318
|
+
|
|
4319
|
+
This hook returns name of current component.
|
|
4320
|
+
|
|
4321
|
+
*src/Component.tsx*
|
|
4322
|
+
```typescript jsx
|
|
4323
|
+
import { useComponentName } from '@innet/sever'
|
|
4324
|
+
|
|
4325
|
+
export function Component () {
|
|
4326
|
+
// returns this ^-------^
|
|
4327
|
+
const name = useComponentName()
|
|
4328
|
+
|
|
4329
|
+
return <success>{{ name }}</success>
|
|
4330
|
+
}
|
|
4331
|
+
```
|
|
4332
|
+
|
|
3499
4333
|
## Issues
|
|
3500
4334
|
If you find a bug or have a suggestion, please file an issue on [GitHub](https://github.com/d8corp/innet-server/issues).
|
|
3501
4335
|
|