@innet/server 2.0.0-alpha.8 → 2.0.0-beta.1
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 +1200 -440
- package/_virtual/_rollup-plugin-process-env.es6.js +10 -0
- package/_virtual/_rollup-plugin-process-env.js +12 -0
- package/handler/handler.d.ts +27 -14
- package/handler/handler.es6.js +17 -11
- package/handler/handler.js +17 -11
- package/hooks/index.d.ts +6 -1
- package/hooks/index.es6.js +6 -1
- package/hooks/index.js +6 -1
- 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/useClientIp.d.ts +1 -1
- package/hooks/useClientIp/useClientIp.es6.js +4 -10
- package/hooks/useClientIp/useClientIp.js +4 -10
- 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/useNewSchema/useNewSchema.es6.js +1 -1
- package/hooks/useNewSchema/useNewSchema.js +1 -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/useRequestHandler/index.d.ts +1 -0
- package/hooks/useRequestHandler/index.es6.js +1 -0
- package/hooks/useRequestHandler/index.js +10 -0
- package/hooks/useRequestHandler/useRequestHandler.d.ts +4 -0
- package/hooks/useRequestHandler/useRequestHandler.es6.js +14 -0
- package/hooks/useRequestHandler/useRequestHandler.js +19 -0
- 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 -9
- package/index.js +33 -14
- package/package.json +2 -3
- package/plugins/main/api/api.d.ts +11 -8
- package/plugins/main/api/api.es6.js +55 -56
- package/plugins/main/api/api.js +54 -55
- package/plugins/main/body/body.d.ts +1 -0
- package/plugins/main/contact/contact.d.ts +2 -2
- package/plugins/main/endpoint/endpoint.d.ts +16 -15
- package/plugins/main/endpoint/endpoint.es6.js +8 -6
- package/plugins/main/endpoint/endpoint.js +7 -5
- 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 +12 -11
- package/plugins/main/param/param.es6.js +6 -6
- package/plugins/main/param/param.js +5 -5
- 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 -1
- package/plugins/main/response/response.es6.js +22 -13
- package/plugins/main/response/response.js +21 -11
- 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 +6 -5
- package/plugins/main/server/server.es6.js +43 -16
- package/plugins/main/server/server.js +42 -15
- package/plugins/main/tag/tag.d.ts +3 -2
- package/plugins/main/tag/tag.es6.js +6 -4
- package/plugins/main/tag/tag.js +5 -3
- 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.d.ts +1 -0
- package/plugins/request/cms/cms.es6.js +3 -4
- package/plugins/request/cms/cms.js +2 -3
- package/plugins/request/cookie/cookie.es6.js +3 -19
- package/plugins/request/cookie/cookie.js +3 -23
- package/plugins/request/error/error.d.ts +41 -40
- package/plugins/request/error/error.es6.js +48 -45
- package/plugins/request/error/error.js +47 -44
- package/plugins/request/file/file.d.ts +1 -0
- package/plugins/request/file/file.es6.js +5 -6
- package/plugins/request/file/file.js +4 -5
- 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 +8 -6
- package/plugins/request/success/success.es6.js +21 -11
- package/plugins/request/success/success.js +20 -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/array/array.d.ts +1 -0
- package/plugins/schema/array/array.es6.js +3 -3
- package/plugins/schema/array/array.js +2 -2
- package/plugins/schema/binary/binary.d.ts +3 -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 +2 -0
- package/plugins/schema/field/field.es6.js +8 -8
- package/plugins/schema/field/field.js +6 -6
- 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.d.ts +1 -0
- package/plugins/schema/object/object.es6.js +20 -7
- package/plugins/schema/object/object.js +19 -6
- 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/schema/tuple/tuple.d.ts +1 -0
- package/plugins/schema/tuple/tuple.es6.js +5 -5
- package/plugins/schema/tuple/tuple.js +4 -4
- package/plugins/schema/uuid/uuid.es6.js +1 -1
- package/plugins/schema/uuid/uuid.js +1 -1
- package/plugins/utils/blacklist/blacklist.d.ts +5 -0
- package/plugins/utils/blacklist/blacklist.es6.js +17 -0
- package/plugins/utils/blacklist/blacklist.js +21 -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 +2 -1
- package/plugins/utils/dts/dts.es6.js +2 -2
- package/plugins/utils/dts/dts.js +2 -2
- package/plugins/utils/env/env.d.ts +7 -0
- package/plugins/utils/env/env.es6.js +11 -0
- package/plugins/utils/{prod/prod.js → env/env.js} +5 -4
- 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 +9 -0
- package/plugins/utils/protection/protection.es6.js +35 -0
- package/plugins/utils/protection/protection.js +39 -0
- package/plugins/utils/swagger/swagger.es6.js +10 -8
- package/plugins/utils/swagger/swagger.js +10 -8
- 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 +5 -0
- package/plugins/utils/whitelist/whitelist.es6.js +19 -0
- package/plugins/utils/whitelist/whitelist.js +23 -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/decorators/once/once.es6.js +1 -1
- package/utils/decorators/once/once.js +1 -1
- package/utils/generateTypes/generateTypes.d.ts +2 -2
- package/utils/generateTypes/generateTypes.es6.js +85 -25
- package/utils/generateTypes/generateTypes.js +85 -25
- 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/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 +11 -1
- package/utils/rules/objectOf/objectOf.js +11 -1
- 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/todo/AddTodo/AddTodo.d.ts +0 -1
- package/example/requests/todo/AddTodo/index.d.ts +0 -1
- package/example/requests/todo/DeleteTodo/DeleteTodo.d.ts +0 -1
- package/example/requests/todo/DeleteTodo/index.d.ts +0 -1
- package/example/requests/todo/EditTodo/EditTodo.d.ts +0 -1
- package/example/requests/todo/EditTodo/index.d.ts +0 -1
- package/example/requests/todo/GetTodo/GetTodo.d.ts +0 -1
- package/example/requests/todo/GetTodo/index.d.ts +0 -1
- package/example/requests/todo/GetTodos/GetTodos.d.ts +0 -1
- package/example/requests/todo/GetTodos/index.d.ts +0 -1
- package/example/requests/todo/index.d.ts +0 -5
- package/example/requests/todo/todos.d.ts +0 -1
- package/example/schemas/app/ListQueryParams/ListQueryParams.d.ts +0 -1
- package/example/schemas/app/ListQueryParams/index.d.ts +0 -1
- package/example/schemas/app/ListSchema/ListSchema.d.ts +0 -4
- package/example/schemas/app/ListSchema/index.d.ts +0 -1
- package/example/schemas/app/index.d.ts +0 -2
- package/example/schemas/index.d.ts +0 -2
- package/example/schemas/todo/TodoSchema/TodoSchema.d.ts +0 -4
- package/example/schemas/todo/TodoSchema/index.d.ts +0 -1
- package/example/schemas/todo/index.d.ts +0 -1
- package/example/tags/Todo/Todo.d.ts +0 -1
- package/example/tags/Todo/index.d.ts +0 -1
- package/example/tags/index.d.ts +0 -1
- package/hooks/useRequestPlugin/index.d.ts +0 -1
- package/hooks/useRequestPlugin/index.es6.js +0 -1
- package/hooks/useRequestPlugin/index.js +0 -9
- package/hooks/useRequestPlugin/useRequestPlugin.d.ts +0 -2
- package/hooks/useRequestPlugin/useRequestPlugin.es6.js +0 -13
- package/hooks/useRequestPlugin/useRequestPlugin.js +0 -17
- 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/generateTypes/generateTypes.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
|
|
|
@@ -135,9 +159,9 @@ export default (
|
|
|
135
159
|
)
|
|
136
160
|
```
|
|
137
161
|
|
|
138
|
-
- By default, it uses port `80` for `http` and port `
|
|
139
|
-
- You can use `
|
|
140
|
-
- [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `
|
|
162
|
+
- By default, it uses port `80` for `http` and port `443` for `https`.
|
|
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,109 +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
593
|
### \<swagger>
|
|
325
594
|
|
|
326
|
-
[← back](#utils)
|
|
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
|
|
880
|
+
|
|
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 do not need to import types, use `Api` namespace everywhere.
|
|
400
|
-
Here is an example of generated types usage.
|
|
401
|
-
|
|
402
|
-
```typescript jsx
|
|
403
|
-
import { useParams } from '@innet/server'
|
|
404
|
-
|
|
405
|
-
import { todos } from '../todos'
|
|
406
|
-
|
|
407
|
-
export function DeleteTodo () {
|
|
408
|
-
const { todoId } = useParams<Api.Endpoints['DELETE:/todos/{todoId}']['Params']>()
|
|
409
|
-
|
|
410
|
-
const todoIndex = todos.findIndex(({ id }) => id === todoId)
|
|
411
|
-
|
|
412
|
-
if (todoIndex === -1) {
|
|
413
|
-
return <error code='todoNotFound' status={404} />
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
todos.splice(todoIndex, 1)
|
|
417
|
-
|
|
418
|
-
return <success />
|
|
419
|
-
}
|
|
420
|
-
```
|
|
421
|
-
|
|
422
978
|
## API Info
|
|
423
979
|
|
|
424
980
|
The API information elements are here.
|
|
@@ -987,6 +1543,7 @@ This element MUST be placed inside `<endpoint>`.
|
|
|
987
1543
|
It defines request body for the endpoint.
|
|
988
1544
|
`@innet/server` formats and validate the value automatically (real-time).
|
|
989
1545
|
|
|
1546
|
+
*src/app.tsx*
|
|
990
1547
|
```typescript jsx
|
|
991
1548
|
return (
|
|
992
1549
|
<server>
|
|
@@ -1013,25 +1570,283 @@ return (
|
|
|
1013
1570
|
)
|
|
1014
1571
|
```
|
|
1015
1572
|
|
|
1016
|
-
### \<response>
|
|
1017
|
-
|
|
1018
|
-
[← back](#endpoints)
|
|
1019
|
-
|
|
1020
|
-
This element MUST be placed inside `<endpoint>`.
|
|
1021
|
-
It defines response body for the endpoint.
|
|
1022
|
-
|
|
1023
|
-
|
|
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>`.
|
|
1681
|
+
|
|
1682
|
+
By default, `type` equals `'application/json'`.
|
|
1683
|
+
|
|
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
|
+
```
|
|
1698
|
+
|
|
1699
|
+
## Primitive Data
|
|
1700
|
+
|
|
1701
|
+
[← back](#index)
|
|
1702
|
+
|
|
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)
|
|
1712
|
+
|
|
1713
|
+
---
|
|
1714
|
+
|
|
1715
|
+
### \<any>
|
|
1716
|
+
|
|
1717
|
+
[← back](#primitive-data)
|
|
1718
|
+
|
|
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).
|
|
1722
|
+
|
|
1723
|
+
*src/app.tsx*
|
|
1724
|
+
```typescript jsx
|
|
1725
|
+
export default (
|
|
1726
|
+
<server>
|
|
1727
|
+
<api>
|
|
1728
|
+
<endpoint method='get' path='/todos'>
|
|
1729
|
+
<param
|
|
1730
|
+
in='query'
|
|
1731
|
+
name='search'>
|
|
1732
|
+
<any />
|
|
1733
|
+
</param>
|
|
1734
|
+
</endpoint>
|
|
1735
|
+
</api>
|
|
1736
|
+
</server>
|
|
1737
|
+
)
|
|
1738
|
+
```
|
|
1739
|
+
|
|
1740
|
+
#### default
|
|
1741
|
+
|
|
1742
|
+
A default value for the `any`.
|
|
1743
|
+
|
|
1744
|
+
*src/app.tsx*
|
|
1745
|
+
```typescript jsx
|
|
1746
|
+
export default (
|
|
1747
|
+
<server>
|
|
1748
|
+
<api>
|
|
1749
|
+
<endpoint method='get' path='/users'>
|
|
1750
|
+
<param
|
|
1751
|
+
in='query'
|
|
1752
|
+
name='search'>
|
|
1753
|
+
<any default={null} />
|
|
1754
|
+
</param>
|
|
1755
|
+
</endpoint>
|
|
1756
|
+
</api>
|
|
1757
|
+
</server>
|
|
1758
|
+
)
|
|
1759
|
+
```
|
|
1760
|
+
|
|
1761
|
+
#### example
|
|
1762
|
+
|
|
1763
|
+
An example value.
|
|
1764
|
+
|
|
1765
|
+
*src/app.tsx*
|
|
1766
|
+
```typescript jsx
|
|
1767
|
+
export default (
|
|
1768
|
+
<server>
|
|
1769
|
+
<api>
|
|
1770
|
+
<endpoint method='get' path='/products'>
|
|
1771
|
+
<param
|
|
1772
|
+
in='query'
|
|
1773
|
+
name='active'>
|
|
1774
|
+
<any example={false} />
|
|
1775
|
+
</param>
|
|
1776
|
+
</endpoint>
|
|
1777
|
+
</api>
|
|
1778
|
+
</server>
|
|
1779
|
+
)
|
|
1780
|
+
```
|
|
1781
|
+
|
|
1782
|
+
#### description
|
|
1783
|
+
|
|
1784
|
+
A description of the `any`.
|
|
1785
|
+
|
|
1786
|
+
*src/app.tsx*
|
|
1787
|
+
```typescript jsx
|
|
1788
|
+
export default (
|
|
1789
|
+
<server>
|
|
1790
|
+
<api>
|
|
1791
|
+
<endpoint method='get' path='/products'>
|
|
1792
|
+
<param
|
|
1793
|
+
in='query'
|
|
1794
|
+
name='active'>
|
|
1795
|
+
<any
|
|
1796
|
+
description='Active products param'
|
|
1797
|
+
/>
|
|
1798
|
+
</param>
|
|
1799
|
+
</endpoint>
|
|
1800
|
+
</api>
|
|
1801
|
+
</server>
|
|
1802
|
+
)
|
|
1803
|
+
```
|
|
1804
|
+
|
|
1805
|
+
### \<null>
|
|
1806
|
+
|
|
1807
|
+
[← back](#primitive-data)
|
|
1808
|
+
|
|
1809
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
1810
|
+
It defines `null` value for a parent element.
|
|
1811
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
1812
|
+
|
|
1813
|
+
*src/app.tsx*
|
|
1814
|
+
```typescript jsx
|
|
1815
|
+
export default (
|
|
1816
|
+
<server>
|
|
1817
|
+
<api>
|
|
1818
|
+
<endpoint method='get' path='/todos'>
|
|
1819
|
+
<param
|
|
1820
|
+
in='query'
|
|
1821
|
+
name='search'>
|
|
1822
|
+
<null />
|
|
1823
|
+
</param>
|
|
1824
|
+
</endpoint>
|
|
1825
|
+
</api>
|
|
1826
|
+
</server>
|
|
1827
|
+
)
|
|
1828
|
+
```
|
|
1829
|
+
|
|
1830
|
+
#### description
|
|
1024
1831
|
|
|
1025
|
-
|
|
1832
|
+
A description of the `null`.
|
|
1026
1833
|
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
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
|
+
```
|
|
1035
1850
|
|
|
1036
1851
|
### \<boolean>
|
|
1037
1852
|
|
|
@@ -2313,7 +3128,9 @@ export default (
|
|
|
2313
3128
|
<api>
|
|
2314
3129
|
<endpoint method='post' path='/users'>
|
|
2315
3130
|
<body>
|
|
2316
|
-
<object
|
|
3131
|
+
<object>
|
|
3132
|
+
<string />
|
|
3133
|
+
</object>
|
|
2317
3134
|
</body>
|
|
2318
3135
|
</endpoint>
|
|
2319
3136
|
</api>
|
|
@@ -2374,9 +3191,9 @@ export default (
|
|
|
2374
3191
|
<api>
|
|
2375
3192
|
<endpoint method='post' path='/users'>
|
|
2376
3193
|
<body>
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
3194
|
+
<object
|
|
3195
|
+
description='The object of a user'
|
|
3196
|
+
/>
|
|
2380
3197
|
</body>
|
|
2381
3198
|
</endpoint>
|
|
2382
3199
|
</api>
|
|
@@ -2392,7 +3209,7 @@ The element MUST be placed inside [\<object>](#object).
|
|
|
2392
3209
|
It defines a `field` of an `object` value for a parent element.
|
|
2393
3210
|
`@innet/server` formats and validate the value automatically (real-time).
|
|
2394
3211
|
|
|
2395
|
-
`key` is REQUIRED prop of `<field>`, it defines a field name of the
|
|
3212
|
+
`key` is REQUIRED prop of `<field>`, it defines a field name of the [\<object>](#object).
|
|
2396
3213
|
|
|
2397
3214
|
*src/app.tsx*
|
|
2398
3215
|
```typescript jsx
|
|
@@ -2436,116 +3253,46 @@ export default (
|
|
|
2436
3253
|
)
|
|
2437
3254
|
```
|
|
2438
3255
|
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
Next elements relate to run-time action.
|
|
2442
|
-
This action calls on user request.
|
|
2443
|
-
|
|
2444
|
-
[← back](#index)
|
|
2445
|
-
|
|
2446
|
-
Parent
|
|
2447
|
-
[\<fallback>](#fallback)
|
|
2448
|
-
[\<request>](#request)
|
|
2449
|
-
|
|
2450
|
-
Children
|
|
2451
|
-
[\<success>](#success)
|
|
2452
|
-
[\<error>](#error)
|
|
2453
|
-
[\<proxy>](#proxy)
|
|
2454
|
-
[\<redirect>](#redirect)
|
|
2455
|
-
[\<cms>](#cms)
|
|
2456
|
-
[\<file>](#file)
|
|
2457
|
-
[\<header>](#header)
|
|
2458
|
-
[\<cookie>](#cookie)
|
|
2459
|
-
|
|
2460
|
-
---
|
|
2461
|
-
|
|
2462
|
-
### \<fallback>
|
|
2463
|
-
|
|
2464
|
-
[← back](#run-time)
|
|
2465
|
-
|
|
2466
|
-
By default, `<api>` server returns 404 with empty body.
|
|
2467
|
-
[\<fallback>](#fallback) element defines default server response.
|
|
2468
|
-
This element MUST be placed in `<api>`.
|
|
2469
|
-
You MUST use one [\<fallback>](#fallback) per `<api>`.
|
|
2470
|
-
Can contain elements available inside [\<request>](#request).
|
|
2471
|
-
|
|
2472
|
-
*src/app.tsx*
|
|
2473
|
-
```typescript jsx
|
|
2474
|
-
export default (
|
|
2475
|
-
<server>
|
|
2476
|
-
<api>
|
|
2477
|
-
<fallback>
|
|
2478
|
-
<error
|
|
2479
|
-
code='unknownEndpoint'
|
|
2480
|
-
/>
|
|
2481
|
-
</fallback>
|
|
2482
|
-
</api>
|
|
2483
|
-
</server>
|
|
2484
|
-
)
|
|
2485
|
-
```
|
|
2486
|
-
|
|
2487
|
-
If you open the application on any URL except for `/`, you can see the next response.
|
|
2488
|
-
|
|
2489
|
-
```json
|
|
2490
|
-
{
|
|
2491
|
-
"error": "unknownEndpoint"
|
|
2492
|
-
}
|
|
2493
|
-
```
|
|
2494
|
-
|
|
2495
|
-
The next elements are placed in [\<request>](#request) or [\<fallback>](#fallback)
|
|
2496
|
-
|
|
2497
|
-
### \<request>
|
|
2498
|
-
|
|
2499
|
-
[← back](#run-time)
|
|
3256
|
+
#### deprecated
|
|
2500
3257
|
|
|
2501
|
-
|
|
2502
|
-
It defines run-time call handler for the endpoint.
|
|
3258
|
+
You can deprecate a field.
|
|
2503
3259
|
|
|
2504
3260
|
*src/app.tsx*
|
|
2505
3261
|
```typescript jsx
|
|
2506
3262
|
export default (
|
|
2507
3263
|
<server>
|
|
2508
3264
|
<api>
|
|
2509
|
-
<endpoint method='
|
|
2510
|
-
<
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
3265
|
+
<endpoint method='post' path='/users'>
|
|
3266
|
+
<body>
|
|
3267
|
+
<object>
|
|
3268
|
+
<field key='name' />
|
|
3269
|
+
<field key='surname' />
|
|
3270
|
+
<field deprecated optional key='birthbay' />
|
|
3271
|
+
</object>
|
|
3272
|
+
</body>
|
|
2515
3273
|
</endpoint>
|
|
2516
3274
|
</api>
|
|
2517
3275
|
</server>
|
|
2518
3276
|
)
|
|
2519
3277
|
```
|
|
2520
3278
|
|
|
2521
|
-
|
|
2522
|
-
The component will run when the endpoint will be triggered.
|
|
3279
|
+
## Run-Time
|
|
2523
3280
|
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
import { GetPartners } from './GetPartners'
|
|
3281
|
+
Next elements relate to run-time action.
|
|
3282
|
+
This action calls on user request.
|
|
2527
3283
|
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
)
|
|
2539
|
-
```
|
|
3284
|
+
[← back](#index)
|
|
3285
|
+
|
|
3286
|
+
[\<success>](#success)
|
|
3287
|
+
[\<error>](#error)
|
|
3288
|
+
[\<proxy>](#proxy)
|
|
3289
|
+
[\<redirect>](#redirect)
|
|
3290
|
+
[\<cms>](#cms)
|
|
3291
|
+
[\<file>](#file)
|
|
3292
|
+
[\<header>](#header)
|
|
3293
|
+
[\<cookie>](#cookie)
|
|
2540
3294
|
|
|
2541
|
-
|
|
2542
|
-
```typescript jsx
|
|
2543
|
-
export const GetPartners = () => (
|
|
2544
|
-
<success>
|
|
2545
|
-
{{partners: []}}
|
|
2546
|
-
</success>
|
|
2547
|
-
)
|
|
2548
|
-
```
|
|
3295
|
+
---
|
|
2549
3296
|
|
|
2550
3297
|
### \<success>
|
|
2551
3298
|
|
|
@@ -2557,11 +3304,9 @@ This is a base element to return a success data.
|
|
|
2557
3304
|
```typescript jsx
|
|
2558
3305
|
export default (
|
|
2559
3306
|
<server>
|
|
2560
|
-
<
|
|
2561
|
-
<
|
|
2562
|
-
|
|
2563
|
-
</fallback>
|
|
2564
|
-
</api>
|
|
3307
|
+
<return>
|
|
3308
|
+
<success />
|
|
3309
|
+
</return>
|
|
2565
3310
|
</server>
|
|
2566
3311
|
)
|
|
2567
3312
|
```
|
|
@@ -2576,13 +3321,11 @@ const data = {...}
|
|
|
2576
3321
|
|
|
2577
3322
|
export default (
|
|
2578
3323
|
<server>
|
|
2579
|
-
<
|
|
2580
|
-
<
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
</fallback>
|
|
2585
|
-
</api>
|
|
3324
|
+
<return>
|
|
3325
|
+
<success>
|
|
3326
|
+
{data}
|
|
3327
|
+
</success>
|
|
3328
|
+
</return>
|
|
2586
3329
|
</server>
|
|
2587
3330
|
)
|
|
2588
3331
|
```
|
|
@@ -2599,13 +3342,11 @@ const data = {...}
|
|
|
2599
3342
|
|
|
2600
3343
|
export default (
|
|
2601
3344
|
<server>
|
|
2602
|
-
<
|
|
2603
|
-
<
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
</fallback>
|
|
2608
|
-
</api>
|
|
3345
|
+
<return>
|
|
3346
|
+
<success status='created'>
|
|
3347
|
+
{data}
|
|
3348
|
+
</success>
|
|
3349
|
+
</return>
|
|
2609
3350
|
</server>
|
|
2610
3351
|
)
|
|
2611
3352
|
```
|
|
@@ -2620,13 +3361,29 @@ const data = {...}
|
|
|
2620
3361
|
|
|
2621
3362
|
export default (
|
|
2622
3363
|
<server>
|
|
2623
|
-
<
|
|
2624
|
-
<
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
3364
|
+
<return>
|
|
3365
|
+
<success status={201}>
|
|
3366
|
+
{data}
|
|
3367
|
+
</success>
|
|
3368
|
+
</return>
|
|
3369
|
+
</server>
|
|
3370
|
+
)
|
|
3371
|
+
```
|
|
3372
|
+
|
|
3373
|
+
#### contentType
|
|
3374
|
+
|
|
3375
|
+
This props sets response content type.
|
|
3376
|
+
By default, it checks children element to define the prop.
|
|
3377
|
+
|
|
3378
|
+
*src/app.tsx*
|
|
3379
|
+
```typescript jsx
|
|
3380
|
+
export default (
|
|
3381
|
+
<server>
|
|
3382
|
+
<return>
|
|
3383
|
+
<success contentType='text/html'>
|
|
3384
|
+
Hello World!
|
|
3385
|
+
</success>
|
|
3386
|
+
</return>
|
|
2630
3387
|
</server>
|
|
2631
3388
|
)
|
|
2632
3389
|
```
|
|
@@ -2636,17 +3393,15 @@ export default (
|
|
|
2636
3393
|
[← back](#run-time)
|
|
2637
3394
|
|
|
2638
3395
|
Returns an error.
|
|
2639
|
-
This element MUST be placed in [\<
|
|
3396
|
+
This element MUST be placed in [\<return>](#return).
|
|
2640
3397
|
|
|
2641
3398
|
*src/app.tsx*
|
|
2642
3399
|
```typescript jsx
|
|
2643
3400
|
export default (
|
|
2644
3401
|
<server>
|
|
2645
|
-
<
|
|
2646
|
-
<
|
|
2647
|
-
|
|
2648
|
-
</fallback>
|
|
2649
|
-
</api>
|
|
3402
|
+
<return>
|
|
3403
|
+
<error />
|
|
3404
|
+
</return>
|
|
2650
3405
|
</server>
|
|
2651
3406
|
)
|
|
2652
3407
|
```
|
|
@@ -2659,13 +3414,11 @@ const data = {...}
|
|
|
2659
3414
|
|
|
2660
3415
|
export default (
|
|
2661
3416
|
<server>
|
|
2662
|
-
<
|
|
2663
|
-
<
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
</fallback>
|
|
2668
|
-
</api>
|
|
3417
|
+
<return>
|
|
3418
|
+
<error>
|
|
3419
|
+
{data}
|
|
3420
|
+
</error>
|
|
3421
|
+
</return>
|
|
2669
3422
|
</server>
|
|
2670
3423
|
)
|
|
2671
3424
|
```
|
|
@@ -2681,13 +3434,11 @@ const data = {
|
|
|
2681
3434
|
|
|
2682
3435
|
export default (
|
|
2683
3436
|
<server>
|
|
2684
|
-
<
|
|
2685
|
-
<
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
</fallback>
|
|
2690
|
-
</api>
|
|
3437
|
+
<return>
|
|
3438
|
+
<error status='notFound'>
|
|
3439
|
+
{data}
|
|
3440
|
+
</error>
|
|
3441
|
+
</return>
|
|
2691
3442
|
</server>
|
|
2692
3443
|
)
|
|
2693
3444
|
```
|
|
@@ -2702,13 +3453,11 @@ const data = {
|
|
|
2702
3453
|
|
|
2703
3454
|
export default (
|
|
2704
3455
|
<server>
|
|
2705
|
-
<
|
|
2706
|
-
<
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
</fallback>
|
|
2711
|
-
</api>
|
|
3456
|
+
<return>
|
|
3457
|
+
<error status={404}>
|
|
3458
|
+
{data}
|
|
3459
|
+
</error>
|
|
3460
|
+
</return>
|
|
2712
3461
|
</server>
|
|
2713
3462
|
)
|
|
2714
3463
|
```
|
|
@@ -2736,15 +3485,13 @@ const data = {
|
|
|
2736
3485
|
|
|
2737
3486
|
export default (
|
|
2738
3487
|
<server>
|
|
2739
|
-
<
|
|
2740
|
-
<
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
</fallback>
|
|
2747
|
-
</api>
|
|
3488
|
+
<return>
|
|
3489
|
+
<error
|
|
3490
|
+
code='noUser'
|
|
3491
|
+
status='notFound'>
|
|
3492
|
+
{data}
|
|
3493
|
+
</error>
|
|
3494
|
+
</return>
|
|
2748
3495
|
</server>
|
|
2749
3496
|
)
|
|
2750
3497
|
```
|
|
@@ -2772,7 +3519,7 @@ There are some default errors:
|
|
|
2772
3519
|
|
|
2773
3520
|
[← back](#run-time)
|
|
2774
3521
|
|
|
2775
|
-
MUST be placed in [\<
|
|
3522
|
+
MUST be placed in [\<return>](#return).
|
|
2776
3523
|
|
|
2777
3524
|
You can easy proxy endpoints to another server/service.
|
|
2778
3525
|
|
|
@@ -2784,14 +3531,14 @@ export default (
|
|
|
2784
3531
|
<endpoint
|
|
2785
3532
|
path='/test'
|
|
2786
3533
|
method='get'>
|
|
2787
|
-
<
|
|
3534
|
+
<return>
|
|
2788
3535
|
<proxy to='https://...' />
|
|
2789
|
-
</
|
|
3536
|
+
</return>
|
|
2790
3537
|
</endpoint>
|
|
2791
|
-
<fallback>
|
|
2792
|
-
<proxy to='https://...' />
|
|
2793
|
-
</fallback>
|
|
2794
3538
|
</api>
|
|
3539
|
+
<return>
|
|
3540
|
+
<proxy to='https://...' />
|
|
3541
|
+
</return>
|
|
2795
3542
|
</server>
|
|
2796
3543
|
)
|
|
2797
3544
|
```
|
|
@@ -2800,7 +3547,7 @@ export default (
|
|
|
2800
3547
|
|
|
2801
3548
|
[← back](#run-time)
|
|
2802
3549
|
|
|
2803
|
-
MUST be placed in [\<
|
|
3550
|
+
MUST be placed in [\<return>](#return).
|
|
2804
3551
|
|
|
2805
3552
|
You can redirect users to another resource. It adds `Cache-Control` header by default.
|
|
2806
3553
|
|
|
@@ -2812,14 +3559,14 @@ export default (
|
|
|
2812
3559
|
<endpoint
|
|
2813
3560
|
path='/test'
|
|
2814
3561
|
method='get'>
|
|
2815
|
-
<
|
|
3562
|
+
<return>
|
|
2816
3563
|
<redirect to='https://...' />
|
|
2817
|
-
</
|
|
3564
|
+
</return>
|
|
2818
3565
|
</endpoint>
|
|
2819
|
-
<fallback>
|
|
2820
|
-
<redirect to='https://...' />
|
|
2821
|
-
</fallback>
|
|
2822
3566
|
</api>
|
|
3567
|
+
<return>
|
|
3568
|
+
<redirect to='https://...' />
|
|
3569
|
+
</return>
|
|
2823
3570
|
</server>
|
|
2824
3571
|
)
|
|
2825
3572
|
```
|
|
@@ -2837,20 +3584,20 @@ export default (
|
|
|
2837
3584
|
<endpoint
|
|
2838
3585
|
path='/test'
|
|
2839
3586
|
method='get'>
|
|
2840
|
-
<
|
|
3587
|
+
<return>
|
|
2841
3588
|
<redirect
|
|
2842
3589
|
status='found'
|
|
2843
3590
|
to='https://...'
|
|
2844
3591
|
/>
|
|
2845
|
-
</
|
|
3592
|
+
</return>
|
|
2846
3593
|
</endpoint>
|
|
2847
|
-
<fallback>
|
|
2848
|
-
<redirect
|
|
2849
|
-
status={303}
|
|
2850
|
-
to='https://...'
|
|
2851
|
-
/>
|
|
2852
|
-
</fallback>
|
|
2853
3594
|
</api>
|
|
3595
|
+
<return>
|
|
3596
|
+
<redirect
|
|
3597
|
+
status={303}
|
|
3598
|
+
to='https://...'
|
|
3599
|
+
/>
|
|
3600
|
+
</return>
|
|
2854
3601
|
</server>
|
|
2855
3602
|
)
|
|
2856
3603
|
```
|
|
@@ -2859,7 +3606,7 @@ export default (
|
|
|
2859
3606
|
|
|
2860
3607
|
[← back](#run-time)
|
|
2861
3608
|
|
|
2862
|
-
MUST be placed in [\<
|
|
3609
|
+
MUST be placed in [\<return>](#return).
|
|
2863
3610
|
|
|
2864
3611
|
`<cms>` helps to return files from a folder by path. It checks files run-time on the server.
|
|
2865
3612
|
|
|
@@ -2867,18 +3614,16 @@ MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
|
2867
3614
|
```typescript jsx
|
|
2868
3615
|
export default (
|
|
2869
3616
|
<server>
|
|
2870
|
-
<
|
|
2871
|
-
<
|
|
2872
|
-
|
|
2873
|
-
</fallback>
|
|
2874
|
-
</api>
|
|
3617
|
+
<return>
|
|
3618
|
+
<cms />
|
|
3619
|
+
</return>
|
|
2875
3620
|
</server>
|
|
2876
3621
|
)
|
|
2877
3622
|
```
|
|
2878
3623
|
|
|
2879
3624
|
#### dir
|
|
2880
3625
|
|
|
2881
|
-
By default, it
|
|
3626
|
+
By default, it equals `INNET_CMS_DIR` node env variable or the project folder.
|
|
2882
3627
|
If you try the previous example on [http://localhost/package.json](http://localhost/package.json)
|
|
2883
3628
|
you get the project `package.json` file.
|
|
2884
3629
|
|
|
@@ -2888,11 +3633,9 @@ You can change root folder by `dir` property.
|
|
|
2888
3633
|
```typescript jsx
|
|
2889
3634
|
export default (
|
|
2890
3635
|
<server>
|
|
2891
|
-
<
|
|
2892
|
-
<
|
|
2893
|
-
|
|
2894
|
-
</fallback>
|
|
2895
|
-
</api>
|
|
3636
|
+
<return>
|
|
3637
|
+
<cms dir='src' />
|
|
3638
|
+
</return>
|
|
2896
3639
|
</server>
|
|
2897
3640
|
)
|
|
2898
3641
|
```
|
|
@@ -2903,15 +3646,16 @@ you get the index file in `src` folder.
|
|
|
2903
3646
|
#### prefix
|
|
2904
3647
|
|
|
2905
3648
|
`<cms>` matches full `path`, you should take it into account if you add `prefix` on `<api>`.
|
|
3649
|
+
By default, it equals `INNET_CMS_PREFIX` node env variable or `/`.
|
|
2906
3650
|
|
|
2907
3651
|
*src/app.tsx*
|
|
2908
3652
|
```typescript jsx
|
|
2909
3653
|
export default (
|
|
2910
3654
|
<server>
|
|
2911
3655
|
<api prefix='/src'>
|
|
2912
|
-
<
|
|
3656
|
+
<return>
|
|
2913
3657
|
<cms />
|
|
2914
|
-
</
|
|
3658
|
+
</return>
|
|
2915
3659
|
</api>
|
|
2916
3660
|
</server>
|
|
2917
3661
|
)
|
|
@@ -2927,9 +3671,9 @@ You can reduce the path for matching by prefix property of `<cms>`.
|
|
|
2927
3671
|
export default (
|
|
2928
3672
|
<server>
|
|
2929
3673
|
<api prefix='/api'>
|
|
2930
|
-
<
|
|
3674
|
+
<return>
|
|
2931
3675
|
<cms prefix='/api' />
|
|
2932
|
-
</
|
|
3676
|
+
</return>
|
|
2933
3677
|
</api>
|
|
2934
3678
|
</server>
|
|
2935
3679
|
)
|
|
@@ -2945,13 +3689,11 @@ You can handle if a file was not found by children elements of `<cms>`.
|
|
|
2945
3689
|
```typescript jsx
|
|
2946
3690
|
export default (
|
|
2947
3691
|
<server>
|
|
2948
|
-
<
|
|
2949
|
-
<
|
|
2950
|
-
<
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
</fallback>
|
|
2954
|
-
</api>
|
|
3692
|
+
<return>
|
|
3693
|
+
<cms>
|
|
3694
|
+
<error status={404} />
|
|
3695
|
+
</cms>
|
|
3696
|
+
</return>
|
|
2955
3697
|
</server>
|
|
2956
3698
|
)
|
|
2957
3699
|
```
|
|
@@ -2960,7 +3702,7 @@ export default (
|
|
|
2960
3702
|
|
|
2961
3703
|
[← back](#run-time)
|
|
2962
3704
|
|
|
2963
|
-
It returns a file. MUST be placed in [\<
|
|
3705
|
+
It returns a file. MUST be placed in [\<return>](#return).
|
|
2964
3706
|
|
|
2965
3707
|
It adds `Content-Length` and `Content-Type` automatically.
|
|
2966
3708
|
|
|
@@ -2970,13 +3712,9 @@ It has a REQUIRED property of `path`.
|
|
|
2970
3712
|
```typescript jsx
|
|
2971
3713
|
export default (
|
|
2972
3714
|
<server>
|
|
2973
|
-
<
|
|
2974
|
-
<
|
|
2975
|
-
|
|
2976
|
-
path='package.json'
|
|
2977
|
-
/>
|
|
2978
|
-
</fallback>
|
|
2979
|
-
</api>
|
|
3715
|
+
<return>
|
|
3716
|
+
<file path='package.json' />
|
|
3717
|
+
</return>
|
|
2980
3718
|
</server>
|
|
2981
3719
|
)
|
|
2982
3720
|
```
|
|
@@ -2991,20 +3729,18 @@ You can handle if a file was not found by children elements of `<file>`.
|
|
|
2991
3729
|
```typescript jsx
|
|
2992
3730
|
export default (
|
|
2993
3731
|
<server>
|
|
2994
|
-
<
|
|
2995
|
-
<
|
|
2996
|
-
<
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
</fallback>
|
|
3000
|
-
</api>
|
|
3732
|
+
<return>
|
|
3733
|
+
<file path='file_is_not_exist.txt'>
|
|
3734
|
+
<error status={404} />
|
|
3735
|
+
</file>
|
|
3736
|
+
</return>
|
|
3001
3737
|
</server>
|
|
3002
3738
|
)
|
|
3003
3739
|
```
|
|
3004
3740
|
|
|
3005
3741
|
### \<header>
|
|
3006
3742
|
|
|
3007
|
-
MUST be placed in [\<
|
|
3743
|
+
MUST be placed in [\<return>](#return).
|
|
3008
3744
|
|
|
3009
3745
|
[← back](#run-time)
|
|
3010
3746
|
|
|
@@ -3014,22 +3750,20 @@ You can add an HTTP header into response by `<header>` element.
|
|
|
3014
3750
|
```typescript jsx
|
|
3015
3751
|
export default (
|
|
3016
3752
|
<server>
|
|
3017
|
-
<
|
|
3018
|
-
<
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
</fallback>
|
|
3025
|
-
</api>
|
|
3753
|
+
<return>
|
|
3754
|
+
<header
|
|
3755
|
+
key='Cache-Control'
|
|
3756
|
+
value='no-cache, no-store, must-revalidate'
|
|
3757
|
+
/>
|
|
3758
|
+
<success />
|
|
3759
|
+
</return>
|
|
3026
3760
|
</server>
|
|
3027
3761
|
)
|
|
3028
3762
|
```
|
|
3029
3763
|
|
|
3030
3764
|
### \<cookie>
|
|
3031
3765
|
|
|
3032
|
-
MUST be placed in [\<
|
|
3766
|
+
MUST be placed in [\<return>](#return).
|
|
3033
3767
|
|
|
3034
3768
|
[← back](#run-time)
|
|
3035
3769
|
|
|
@@ -3039,18 +3773,16 @@ You can add/remove a cookie into response by `<cookie>` element.
|
|
|
3039
3773
|
```typescript jsx
|
|
3040
3774
|
export default (
|
|
3041
3775
|
<server>
|
|
3042
|
-
<
|
|
3043
|
-
<
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
</fallback>
|
|
3053
|
-
</api>
|
|
3776
|
+
<return>
|
|
3777
|
+
<cookie
|
|
3778
|
+
key='token'
|
|
3779
|
+
value='...'
|
|
3780
|
+
/>
|
|
3781
|
+
<cookie
|
|
3782
|
+
key='removedCookie'
|
|
3783
|
+
/>
|
|
3784
|
+
<success />
|
|
3785
|
+
</return>
|
|
3054
3786
|
</server>
|
|
3055
3787
|
)
|
|
3056
3788
|
```
|
|
@@ -3064,16 +3796,14 @@ By default, no domain is set, and most clients will consider the cookie to apply
|
|
|
3064
3796
|
```typescript jsx
|
|
3065
3797
|
export default (
|
|
3066
3798
|
<server>
|
|
3067
|
-
<
|
|
3068
|
-
<
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
</fallback>
|
|
3076
|
-
</api>
|
|
3799
|
+
<return>
|
|
3800
|
+
<cookie
|
|
3801
|
+
domain='.example.com'
|
|
3802
|
+
key='token'
|
|
3803
|
+
value='...'
|
|
3804
|
+
/>
|
|
3805
|
+
<success />
|
|
3806
|
+
</return>
|
|
3077
3807
|
</server>
|
|
3078
3808
|
)
|
|
3079
3809
|
```
|
|
@@ -3092,16 +3822,14 @@ Note the [cookie storage model specification](https://datatracker.ietf.org/doc/h
|
|
|
3092
3822
|
```typescript jsx
|
|
3093
3823
|
export default (
|
|
3094
3824
|
<server>
|
|
3095
|
-
<
|
|
3096
|
-
<
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
</fallback>
|
|
3104
|
-
</api>
|
|
3825
|
+
<return>
|
|
3826
|
+
<cookie
|
|
3827
|
+
expires={new Date('2050-01-01')}
|
|
3828
|
+
key='token'
|
|
3829
|
+
value='...'
|
|
3830
|
+
/>
|
|
3831
|
+
<success />
|
|
3832
|
+
</return>
|
|
3105
3833
|
</server>
|
|
3106
3834
|
)
|
|
3107
3835
|
```
|
|
@@ -3115,16 +3843,14 @@ Note be careful when setting this to true, as compliant clients will not allow c
|
|
|
3115
3843
|
```typescript jsx
|
|
3116
3844
|
export default (
|
|
3117
3845
|
<server>
|
|
3118
|
-
<
|
|
3119
|
-
<
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
</fallback>
|
|
3127
|
-
</api>
|
|
3846
|
+
<return>
|
|
3847
|
+
<cookie
|
|
3848
|
+
httpOnly
|
|
3849
|
+
key='token'
|
|
3850
|
+
value='...'
|
|
3851
|
+
/>
|
|
3852
|
+
<success />
|
|
3853
|
+
</return>
|
|
3128
3854
|
</server>
|
|
3129
3855
|
)
|
|
3130
3856
|
```
|
|
@@ -3138,17 +3864,15 @@ Note the [cookie storage model specification](https://datatracker.ietf.org/doc/h
|
|
|
3138
3864
|
```typescript jsx
|
|
3139
3865
|
export default (
|
|
3140
3866
|
<server>
|
|
3141
|
-
<
|
|
3142
|
-
<
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
</fallback>
|
|
3151
|
-
</api>
|
|
3867
|
+
<return>
|
|
3868
|
+
<cookie
|
|
3869
|
+
httpOnly
|
|
3870
|
+
maxAge={9999}
|
|
3871
|
+
key='token'
|
|
3872
|
+
value='...'
|
|
3873
|
+
/>
|
|
3874
|
+
<success />
|
|
3875
|
+
</return>
|
|
3152
3876
|
</server>
|
|
3153
3877
|
)
|
|
3154
3878
|
```
|
|
@@ -3162,18 +3886,16 @@ By default, the path is considered the “default path”.
|
|
|
3162
3886
|
```typescript jsx
|
|
3163
3887
|
export default (
|
|
3164
3888
|
<server>
|
|
3165
|
-
<
|
|
3166
|
-
<
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
</fallback>
|
|
3176
|
-
</api>
|
|
3889
|
+
<return>
|
|
3890
|
+
<cookie
|
|
3891
|
+
httpOnly
|
|
3892
|
+
maxAge={9999}
|
|
3893
|
+
path='/src'
|
|
3894
|
+
key='token'
|
|
3895
|
+
value='...'
|
|
3896
|
+
/>
|
|
3897
|
+
<success />
|
|
3898
|
+
</return>
|
|
3177
3899
|
</server>
|
|
3178
3900
|
)
|
|
3179
3901
|
```
|
|
@@ -3192,18 +3914,16 @@ note This is an attribute that has not yet been fully standardized, and may chan
|
|
|
3192
3914
|
```typescript jsx
|
|
3193
3915
|
export default (
|
|
3194
3916
|
<server>
|
|
3195
|
-
<
|
|
3196
|
-
<
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
</fallback>
|
|
3206
|
-
</api>
|
|
3917
|
+
<return>
|
|
3918
|
+
<cookie
|
|
3919
|
+
httpOnly
|
|
3920
|
+
priority='high'
|
|
3921
|
+
path='/src'
|
|
3922
|
+
key='token'
|
|
3923
|
+
value='...'
|
|
3924
|
+
/>
|
|
3925
|
+
<success />
|
|
3926
|
+
</return>
|
|
3207
3927
|
</server>
|
|
3208
3928
|
)
|
|
3209
3929
|
```
|
|
@@ -3225,19 +3945,17 @@ This also means many clients may ignore this attribute until they understand it.
|
|
|
3225
3945
|
```typescript jsx
|
|
3226
3946
|
export default (
|
|
3227
3947
|
<server>
|
|
3228
|
-
<
|
|
3229
|
-
<
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
</fallback>
|
|
3240
|
-
</api>
|
|
3948
|
+
<return>
|
|
3949
|
+
<cookie
|
|
3950
|
+
httpOnly
|
|
3951
|
+
sameSite
|
|
3952
|
+
priority='high'
|
|
3953
|
+
path='/src'
|
|
3954
|
+
key='token'
|
|
3955
|
+
value='...'
|
|
3956
|
+
/>
|
|
3957
|
+
<success />
|
|
3958
|
+
</return>
|
|
3241
3959
|
</server>
|
|
3242
3960
|
)
|
|
3243
3961
|
```
|
|
@@ -3254,17 +3972,15 @@ Note be careful when setting this to true, as compliant clients will not send th
|
|
|
3254
3972
|
```typescript jsx
|
|
3255
3973
|
export default (
|
|
3256
3974
|
<server>
|
|
3257
|
-
<
|
|
3258
|
-
<
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
</fallback>
|
|
3267
|
-
</api>
|
|
3975
|
+
<return>
|
|
3976
|
+
<cookie
|
|
3977
|
+
httpOnly
|
|
3978
|
+
secure
|
|
3979
|
+
key='token'
|
|
3980
|
+
value='...'
|
|
3981
|
+
/>
|
|
3982
|
+
<success />
|
|
3983
|
+
</return>
|
|
3268
3984
|
</server>
|
|
3269
3985
|
)
|
|
3270
3986
|
```
|
|
@@ -3297,14 +4013,12 @@ import { SetToken } from './SetToken'
|
|
|
3297
4013
|
|
|
3298
4014
|
export default (
|
|
3299
4015
|
<server>
|
|
3300
|
-
<
|
|
3301
|
-
<
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
</fallback>
|
|
3307
|
-
</api>
|
|
4016
|
+
<return>
|
|
4017
|
+
<SetToken
|
|
4018
|
+
value='...'
|
|
4019
|
+
/>
|
|
4020
|
+
<success />
|
|
4021
|
+
</return>
|
|
3308
4022
|
</server>
|
|
3309
4023
|
)
|
|
3310
4024
|
```
|
|
@@ -3329,10 +4043,12 @@ Real-time
|
|
|
3329
4043
|
[useClientIp](#useclientip)
|
|
3330
4044
|
|
|
3331
4045
|
Server start
|
|
3332
|
-
[
|
|
4046
|
+
[useServerPlugin](#useserverplugin)
|
|
3333
4047
|
|
|
3334
4048
|
Both
|
|
3335
4049
|
[useServer](#useserver)
|
|
4050
|
+
[usePort](#useport)
|
|
4051
|
+
[useIsServerHttps](#useisserverhttps)
|
|
3336
4052
|
[useComponentName](#usecomponentname)
|
|
3337
4053
|
|
|
3338
4054
|
---
|
|
@@ -3341,7 +4057,7 @@ Both
|
|
|
3341
4057
|
|
|
3342
4058
|
[← back](#hooks)
|
|
3343
4059
|
|
|
3344
|
-
This hook MUST be used in a component placed in [\<
|
|
4060
|
+
This hook MUST be used in a component placed in [\<return>](#return).
|
|
3345
4061
|
This hook returns current request instance.
|
|
3346
4062
|
|
|
3347
4063
|
*src/Component.tsx*
|
|
@@ -3362,7 +4078,7 @@ export function Component () {
|
|
|
3362
4078
|
|
|
3363
4079
|
[← back](#hooks)
|
|
3364
4080
|
|
|
3365
|
-
This hook MUST be used in a component placed in [\<
|
|
4081
|
+
This hook MUST be used in a component placed in [\<return>](#return).
|
|
3366
4082
|
This hook returns current response instance.
|
|
3367
4083
|
|
|
3368
4084
|
*src/Component.tsx*
|
|
@@ -3383,7 +4099,7 @@ export function Component () {
|
|
|
3383
4099
|
|
|
3384
4100
|
[← back](#hooks)
|
|
3385
4101
|
|
|
3386
|
-
This hook MUST be used in a component placed in [\<
|
|
4102
|
+
This hook MUST be used in a component placed in [\<return>](#return).
|
|
3387
4103
|
This hook returns current request headers object.
|
|
3388
4104
|
|
|
3389
4105
|
*src/Component.tsx*
|
|
@@ -3402,7 +4118,7 @@ export function Component () {
|
|
|
3402
4118
|
|
|
3403
4119
|
[← back](#hooks)
|
|
3404
4120
|
|
|
3405
|
-
This hook MUST be used in a component placed in [\<
|
|
4121
|
+
This hook MUST be used in a component placed in [\<return>](#return).
|
|
3406
4122
|
This hook returns current request cookies object.
|
|
3407
4123
|
|
|
3408
4124
|
*src/Component.tsx*
|
|
@@ -3421,7 +4137,7 @@ export function Component () {
|
|
|
3421
4137
|
|
|
3422
4138
|
[← back](#hooks)
|
|
3423
4139
|
|
|
3424
|
-
This hook MUST be used in a component placed in [\<
|
|
4140
|
+
This hook MUST be used in a component placed in [\<return>](#return).
|
|
3425
4141
|
This hook returns current request URL path as a `string`.
|
|
3426
4142
|
|
|
3427
4143
|
*src/Component.tsx*
|
|
@@ -3440,7 +4156,7 @@ export function Component () {
|
|
|
3440
4156
|
|
|
3441
4157
|
[← back](#hooks)
|
|
3442
4158
|
|
|
3443
|
-
This hook MUST be used in a component placed in [\<
|
|
4159
|
+
This hook MUST be used in a component placed in [\<return>](#return).
|
|
3444
4160
|
This hook returns an object of URL params you set by [\<param>](#param).
|
|
3445
4161
|
|
|
3446
4162
|
*src/Component.tsx*
|
|
@@ -3458,7 +4174,7 @@ export function Component () {
|
|
|
3458
4174
|
|
|
3459
4175
|
[← back](#hooks)
|
|
3460
4176
|
|
|
3461
|
-
This hook MUST be used in a component placed in [\<
|
|
4177
|
+
This hook MUST be used in a component placed in [\<return>](#return).
|
|
3462
4178
|
This hook returns an object of URL query params.
|
|
3463
4179
|
|
|
3464
4180
|
*src/Component.tsx*
|
|
@@ -3476,7 +4192,7 @@ export function Component () {
|
|
|
3476
4192
|
|
|
3477
4193
|
[← back](#hooks)
|
|
3478
4194
|
|
|
3479
|
-
This hook MUST be used in a component placed in [\<
|
|
4195
|
+
This hook MUST be used in a component placed in [\<return>](#return).
|
|
3480
4196
|
This hook returns current request body.
|
|
3481
4197
|
|
|
3482
4198
|
*src/Component.tsx*
|
|
@@ -3495,7 +4211,7 @@ export function Component () {
|
|
|
3495
4211
|
[← back](#hooks)
|
|
3496
4212
|
|
|
3497
4213
|
This hook returns request user IP.
|
|
3498
|
-
This hook MUST be used in a component placed in [\<
|
|
4214
|
+
This hook MUST be used in a component placed in [\<return>](#return).
|
|
3499
4215
|
|
|
3500
4216
|
*src/Component.tsx*
|
|
3501
4217
|
```typescript jsx
|
|
@@ -3508,7 +4224,7 @@ export function Component () {
|
|
|
3508
4224
|
}
|
|
3509
4225
|
```
|
|
3510
4226
|
|
|
3511
|
-
###
|
|
4227
|
+
### useServerPlugin
|
|
3512
4228
|
|
|
3513
4229
|
[← back](#hooks)
|
|
3514
4230
|
|
|
@@ -3516,25 +4232,24 @@ This hook adds a request plugin function.
|
|
|
3516
4232
|
The function runs before check endpoints.
|
|
3517
4233
|
If the function returns `true` the request handling stops, and you get full control over the request.
|
|
3518
4234
|
|
|
3519
|
-
This hook MUST be used in a component placed in [\<
|
|
4235
|
+
This hook MUST be used in a component placed in [\<server>](#server).
|
|
3520
4236
|
|
|
3521
4237
|
*src/SecretEndpoint.tsx*
|
|
3522
4238
|
```typescript jsx
|
|
3523
|
-
import { useRequestPlugin } from '@innet/sever'
|
|
4239
|
+
import { useRequestPlugin, useAction } from '@innet/sever'
|
|
3524
4240
|
|
|
3525
4241
|
export function SecretEndpoint () {
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
return true
|
|
4242
|
+
useServerPlugin(() => {
|
|
4243
|
+
const action = useAction()
|
|
4244
|
+
|
|
4245
|
+
if (action.path.startsWith('/secret-endpoint')) {
|
|
4246
|
+
return <success>A secret message</success>
|
|
3532
4247
|
}
|
|
3533
4248
|
})
|
|
3534
4249
|
}
|
|
3535
4250
|
```
|
|
3536
4251
|
|
|
3537
|
-
Then use the plugin in [\<api>](#api).
|
|
4252
|
+
Then use the plugin in [\<server>](#server) or [\<api>](#api).
|
|
3538
4253
|
|
|
3539
4254
|
*src/app.tsx*
|
|
3540
4255
|
```typescript jsx
|
|
@@ -3542,12 +4257,10 @@ import { SecretEndpoint } from './SecretEndpoint'
|
|
|
3542
4257
|
|
|
3543
4258
|
export default (
|
|
3544
4259
|
<server>
|
|
3545
|
-
<
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
<SecretEndpoint />
|
|
3550
|
-
</api>
|
|
4260
|
+
<SecretEndpoint />
|
|
4261
|
+
<return>
|
|
4262
|
+
<error />
|
|
4263
|
+
</return>
|
|
3551
4264
|
</server>
|
|
3552
4265
|
)
|
|
3553
4266
|
```
|
|
@@ -3575,6 +4288,53 @@ export function Component () {
|
|
|
3575
4288
|
}
|
|
3576
4289
|
```
|
|
3577
4290
|
|
|
4291
|
+
### usePort
|
|
4292
|
+
|
|
4293
|
+
[← back](#hooks)
|
|
4294
|
+
|
|
4295
|
+
This hook MUST be used in a component placed in [\<server>](#server).
|
|
4296
|
+
This hook returns current http(s) server port.
|
|
4297
|
+
|
|
4298
|
+
*src/LocalHost.tsx*
|
|
4299
|
+
```typescript jsx
|
|
4300
|
+
import { usePort } from '@innet/sever'
|
|
4301
|
+
|
|
4302
|
+
export function LocalHost () {
|
|
4303
|
+
const port = usePort()
|
|
4304
|
+
|
|
4305
|
+
return (
|
|
4306
|
+
<host
|
|
4307
|
+
description='Development'
|
|
4308
|
+
url={`http://localhost:${port}/api`}
|
|
4309
|
+
/>
|
|
4310
|
+
)
|
|
4311
|
+
}
|
|
4312
|
+
```
|
|
4313
|
+
|
|
4314
|
+
### useIsServerHttps
|
|
4315
|
+
|
|
4316
|
+
[← back](#hooks)
|
|
4317
|
+
|
|
4318
|
+
This hook MUST be used in a component placed in [\<server>](#server).
|
|
4319
|
+
This hook returns `true` if it is https server and `false` if not.
|
|
4320
|
+
|
|
4321
|
+
*src/LocalHost.tsx*
|
|
4322
|
+
```typescript jsx
|
|
4323
|
+
import { usePort, useIsServerHttps } from '@innet/sever'
|
|
4324
|
+
|
|
4325
|
+
export function LocalHost () {
|
|
4326
|
+
const https = useIsServerHttps() ? 'https' : 'http'
|
|
4327
|
+
const port = usePort()
|
|
4328
|
+
|
|
4329
|
+
return (
|
|
4330
|
+
<host
|
|
4331
|
+
description='Development'
|
|
4332
|
+
url={`${https}://localhost:${port}/api`}
|
|
4333
|
+
/>
|
|
4334
|
+
)
|
|
4335
|
+
}
|
|
4336
|
+
```
|
|
4337
|
+
|
|
3578
4338
|
### useComponentName
|
|
3579
4339
|
|
|
3580
4340
|
[← back](#hooks)
|