@innet/server 2.0.0-alpha.9 → 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.
Files changed (315) hide show
  1. package/README.md +1041 -445
  2. package/_virtual/_rollup-plugin-process-env.es6.js +10 -0
  3. package/_virtual/_rollup-plugin-process-env.js +12 -0
  4. package/handler/handler.d.ts +25 -14
  5. package/handler/handler.es6.js +15 -11
  6. package/handler/handler.js +15 -11
  7. package/hooks/index.d.ts +6 -1
  8. package/hooks/index.es6.js +6 -1
  9. package/hooks/index.js +6 -1
  10. package/hooks/useAction/useAction.es6.js +1 -1
  11. package/hooks/useAction/useAction.js +1 -1
  12. package/hooks/useApi/useApi.d.ts +1 -3
  13. package/hooks/useClientIp/useClientIp.d.ts +1 -1
  14. package/hooks/useEndpoint/useEndpoint.d.ts +1 -1
  15. package/hooks/useEndpoint/useEndpoint.es6.js +3 -1
  16. package/hooks/useEndpoint/useEndpoint.js +3 -1
  17. package/hooks/useIsServerHttps/index.d.ts +1 -0
  18. package/hooks/useIsServerHttps/index.es6.js +1 -0
  19. package/hooks/useIsServerHttps/index.js +10 -0
  20. package/hooks/useIsServerHttps/useIsServerHttps.d.ts +3 -0
  21. package/hooks/useIsServerHttps/useIsServerHttps.es6.js +14 -0
  22. package/hooks/useIsServerHttps/useIsServerHttps.js +19 -0
  23. package/hooks/useNewSchema/useNewSchema.es6.js +1 -1
  24. package/hooks/useNewSchema/useNewSchema.js +1 -1
  25. package/hooks/useObjectSchemaContext/index.d.ts +1 -0
  26. package/hooks/useObjectSchemaContext/index.es6.js +1 -0
  27. package/hooks/useObjectSchemaContext/index.js +10 -0
  28. package/hooks/useObjectSchemaContext/useObjectSchemaContext.d.ts +3 -0
  29. package/hooks/useObjectSchemaContext/useObjectSchemaContext.es6.js +14 -0
  30. package/hooks/useObjectSchemaContext/useObjectSchemaContext.js +19 -0
  31. package/hooks/useRequest/index.es6.js +1 -1
  32. package/hooks/useRequest/index.js +0 -1
  33. package/hooks/useRequest/useRequest.d.ts +1 -4
  34. package/hooks/useRequest/useRequest.es6.js +4 -4
  35. package/hooks/useRequest/useRequest.js +3 -4
  36. package/hooks/useRequestHandler/index.d.ts +1 -0
  37. package/hooks/useRequestHandler/index.es6.js +1 -0
  38. package/hooks/useRequestHandler/index.js +10 -0
  39. package/hooks/useRequestHandler/useRequestHandler.d.ts +4 -0
  40. package/hooks/useRequestHandler/useRequestHandler.es6.js +14 -0
  41. package/hooks/useRequestHandler/useRequestHandler.js +19 -0
  42. package/hooks/useResponse/index.es6.js +1 -1
  43. package/hooks/useResponse/index.js +0 -1
  44. package/hooks/useResponse/useResponse.d.ts +1 -4
  45. package/hooks/useResponse/useResponse.es6.js +4 -4
  46. package/hooks/useResponse/useResponse.js +3 -4
  47. package/hooks/useSchemaType/useSchemaType.d.ts +3 -2
  48. package/hooks/useSchemaType/useSchemaType.es6.js +5 -6
  49. package/hooks/useSchemaType/useSchemaType.js +5 -6
  50. package/hooks/useServer/useServer.d.ts +2 -1
  51. package/hooks/useServer/useServer.es6.js +3 -1
  52. package/hooks/useServer/useServer.js +3 -1
  53. package/hooks/useServerPlugin/index.d.ts +1 -0
  54. package/hooks/useServerPlugin/index.es6.js +1 -0
  55. package/hooks/useServerPlugin/index.js +9 -0
  56. package/hooks/useServerPlugin/useServerPlugin.d.ts +2 -0
  57. package/hooks/useServerPlugin/useServerPlugin.es6.js +13 -0
  58. package/hooks/useServerPlugin/useServerPlugin.js +17 -0
  59. package/hooks/useServerPlugins/index.d.ts +1 -0
  60. package/hooks/useServerPlugins/index.es6.js +1 -0
  61. package/hooks/useServerPlugins/index.js +10 -0
  62. package/hooks/useServerPlugins/useServerPlugins.d.ts +4 -0
  63. package/hooks/useServerPlugins/useServerPlugins.es6.js +14 -0
  64. package/hooks/useServerPlugins/useServerPlugins.js +19 -0
  65. package/hooks/useServerPort/index.d.ts +1 -0
  66. package/hooks/useServerPort/index.es6.js +1 -0
  67. package/hooks/useServerPort/index.js +10 -0
  68. package/hooks/useServerPort/useServerPort.d.ts +3 -0
  69. package/hooks/useServerPort/useServerPort.es6.js +14 -0
  70. package/hooks/useServerPort/useServerPort.js +19 -0
  71. package/index.es6.js +16 -9
  72. package/index.js +31 -14
  73. package/package.json +2 -3
  74. package/plugins/main/api/api.d.ts +11 -8
  75. package/plugins/main/api/api.es6.js +55 -56
  76. package/plugins/main/api/api.js +54 -55
  77. package/plugins/main/body/body.d.ts +1 -0
  78. package/plugins/main/contact/contact.d.ts +2 -2
  79. package/plugins/main/endpoint/endpoint.d.ts +16 -15
  80. package/plugins/main/endpoint/endpoint.es6.js +8 -6
  81. package/plugins/main/endpoint/endpoint.js +7 -5
  82. package/plugins/main/host/host.d.ts +5 -5
  83. package/plugins/main/index.d.ts +2 -2
  84. package/plugins/main/index.es6.js +2 -2
  85. package/plugins/main/index.js +2 -2
  86. package/plugins/main/license/license.d.ts +5 -5
  87. package/plugins/main/param/param.d.ts +12 -11
  88. package/plugins/main/param/param.es6.js +6 -6
  89. package/plugins/main/param/param.js +5 -5
  90. package/plugins/main/preset/index.d.ts +1 -0
  91. package/plugins/main/preset/index.es6.js +1 -0
  92. package/plugins/{utils/prod → main/preset}/index.js +2 -2
  93. package/plugins/main/preset/preset.d.ts +3 -0
  94. package/plugins/main/preset/preset.es6.js +13 -0
  95. package/plugins/{utils/dev/dev.js → main/preset/preset.js} +9 -6
  96. package/plugins/main/response/index.es6.js +1 -1
  97. package/plugins/main/response/index.js +1 -0
  98. package/plugins/main/response/response.d.ts +6 -1
  99. package/plugins/main/response/response.es6.js +22 -13
  100. package/plugins/main/response/response.js +21 -11
  101. package/plugins/main/return/index.d.ts +1 -0
  102. package/plugins/main/return/index.es6.js +1 -0
  103. package/plugins/main/return/index.js +9 -0
  104. package/plugins/main/return/return.d.ts +4 -0
  105. package/plugins/main/return/return.es6.js +10 -0
  106. package/plugins/main/return/return.js +14 -0
  107. package/plugins/main/server/server.d.ts +6 -5
  108. package/plugins/main/server/server.es6.js +43 -16
  109. package/plugins/main/server/server.js +42 -15
  110. package/plugins/main/tag/tag.d.ts +3 -2
  111. package/plugins/main/tag/tag.es6.js +6 -4
  112. package/plugins/main/tag/tag.js +5 -3
  113. package/plugins/main/variable/variable.d.ts +5 -5
  114. package/plugins/main/variable/variable.es6.js +3 -1
  115. package/plugins/main/variable/variable.js +3 -1
  116. package/plugins/request/cms/cms.d.ts +1 -0
  117. package/plugins/request/cms/cms.es6.js +3 -4
  118. package/plugins/request/cms/cms.js +2 -3
  119. package/plugins/request/error/error.d.ts +41 -40
  120. package/plugins/request/error/error.es6.js +48 -45
  121. package/plugins/request/error/error.js +47 -44
  122. package/plugins/request/file/file.d.ts +1 -0
  123. package/plugins/request/file/file.es6.js +5 -6
  124. package/plugins/request/file/file.js +4 -5
  125. package/plugins/request/header/header.es6.js +1 -1
  126. package/plugins/request/header/header.js +1 -1
  127. package/plugins/request/proxy/proxy.d.ts +4 -1
  128. package/plugins/request/proxy/proxy.es6.js +5 -2
  129. package/plugins/request/proxy/proxy.js +5 -2
  130. package/plugins/request/redirect/redirect.d.ts +8 -7
  131. package/plugins/request/redirect/redirect.es6.js +7 -7
  132. package/plugins/request/redirect/redirect.js +7 -7
  133. package/plugins/request/success/success.d.ts +8 -6
  134. package/plugins/request/success/success.es6.js +21 -11
  135. package/plugins/request/success/success.js +20 -10
  136. package/plugins/schema/any/any.d.ts +5 -0
  137. package/plugins/schema/any/any.es6.js +27 -0
  138. package/plugins/schema/any/any.js +31 -0
  139. package/plugins/schema/array/array.d.ts +1 -0
  140. package/plugins/schema/array/array.es6.js +3 -3
  141. package/plugins/schema/array/array.js +2 -2
  142. package/plugins/schema/binary/binary.d.ts +3 -3
  143. package/plugins/schema/date/date.d.ts +1 -1
  144. package/plugins/schema/date/date.es6.js +3 -3
  145. package/plugins/schema/date/date.js +3 -3
  146. package/plugins/schema/field/field.d.ts +2 -0
  147. package/plugins/schema/field/field.es6.js +8 -8
  148. package/plugins/schema/field/field.js +6 -6
  149. package/plugins/schema/index.d.ts +1 -0
  150. package/plugins/schema/index.es6.js +1 -0
  151. package/plugins/schema/index.js +1 -0
  152. package/plugins/schema/integer/integer.d.ts +3 -3
  153. package/plugins/schema/integer/integer.es6.js +1 -1
  154. package/plugins/schema/integer/integer.js +1 -1
  155. package/plugins/schema/number/number.d.ts +2 -2
  156. package/plugins/schema/number/number.es6.js +1 -1
  157. package/plugins/schema/number/number.js +1 -1
  158. package/plugins/schema/object/object.d.ts +1 -0
  159. package/plugins/schema/object/object.es6.js +20 -7
  160. package/plugins/schema/object/object.js +19 -6
  161. package/plugins/schema/string/string.d.ts +2 -2
  162. package/plugins/schema/string/string.es6.js +44 -30
  163. package/plugins/schema/string/string.js +44 -30
  164. package/plugins/schema/tuple/tuple.d.ts +1 -0
  165. package/plugins/schema/tuple/tuple.es6.js +5 -5
  166. package/plugins/schema/tuple/tuple.js +4 -4
  167. package/plugins/schema/uuid/uuid.es6.js +1 -1
  168. package/plugins/schema/uuid/uuid.js +1 -1
  169. package/plugins/utils/blacklist/blacklist.d.ts +5 -0
  170. package/plugins/utils/blacklist/blacklist.es6.js +17 -0
  171. package/plugins/utils/blacklist/blacklist.js +21 -0
  172. package/plugins/utils/blacklist/index.d.ts +1 -0
  173. package/plugins/utils/blacklist/index.es6.js +1 -0
  174. package/plugins/utils/blacklist/index.js +9 -0
  175. package/plugins/utils/dts/dts.d.ts +2 -1
  176. package/plugins/utils/dts/dts.es6.js +2 -2
  177. package/plugins/utils/dts/dts.js +2 -2
  178. package/plugins/utils/env/env.d.ts +7 -0
  179. package/plugins/utils/env/env.es6.js +11 -0
  180. package/plugins/utils/{prod/prod.js → env/env.js} +5 -4
  181. package/plugins/utils/env/index.d.ts +1 -0
  182. package/plugins/utils/env/index.es6.js +1 -0
  183. package/plugins/utils/{dev → env}/index.js +2 -2
  184. package/plugins/utils/index.d.ts +3 -2
  185. package/plugins/utils/index.es6.js +3 -2
  186. package/plugins/utils/index.js +3 -2
  187. package/plugins/utils/protection/protection.d.ts +4 -4
  188. package/plugins/utils/protection/protection.es6.js +13 -16
  189. package/plugins/utils/protection/protection.js +13 -16
  190. package/plugins/utils/swagger/swagger.es6.js +7 -5
  191. package/plugins/utils/swagger/swagger.js +7 -5
  192. package/plugins/utils/whitelist/index.d.ts +1 -0
  193. package/plugins/utils/whitelist/index.es6.js +1 -0
  194. package/plugins/utils/whitelist/index.js +9 -0
  195. package/plugins/utils/whitelist/whitelist.d.ts +5 -0
  196. package/plugins/utils/whitelist/whitelist.es6.js +19 -0
  197. package/plugins/utils/whitelist/whitelist.js +23 -0
  198. package/types.d.ts +15 -22
  199. package/utils/FileData/Bin.d.ts +13 -13
  200. package/utils/FileData/Bin.es6.js +2 -2
  201. package/utils/FileData/Bin.js +2 -2
  202. package/utils/action/Action.d.ts +12 -12
  203. package/utils/action/Action.es6.js +84 -82
  204. package/utils/action/Action.js +83 -81
  205. package/utils/dateFormat/dateFormat.d.ts +1 -1
  206. package/utils/dateFormat/dateFormat.es6.js +1 -1
  207. package/utils/dateFormat/dateFormat.js +1 -1
  208. package/utils/decorators/once/once.es6.js +1 -1
  209. package/utils/decorators/once/once.js +1 -1
  210. package/utils/generateTypes/generateTypes.d.ts +2 -2
  211. package/utils/generateTypes/generateTypes.es6.js +85 -25
  212. package/utils/generateTypes/generateTypes.js +85 -25
  213. package/utils/getEndpoint/getEndpoint.es6.js +2 -2
  214. package/utils/getEndpoint/getEndpoint.js +2 -2
  215. package/utils/getOrAdd/getOrAdd.d.ts +1 -1
  216. package/utils/httpOnStart/httpOnStart.d.ts +1 -1
  217. package/utils/httpOnStart/httpOnStart.es6.js +1 -1
  218. package/utils/httpOnStart/httpOnStart.js +1 -1
  219. package/utils/rules/binaryAccept/binaryAccept.es6.js +2 -2
  220. package/utils/rules/binaryAccept/binaryAccept.js +2 -2
  221. package/utils/rules/dateTo/dateTo.d.ts +1 -1
  222. package/utils/rules/helpers.d.ts +1 -1
  223. package/utils/rules/index.d.ts +0 -1
  224. package/utils/rules/index.es6.js +0 -1
  225. package/utils/rules/index.js +0 -1
  226. package/utils/rules/int/int.es6.js +2 -2
  227. package/utils/rules/int/int.js +2 -2
  228. package/utils/rules/max/max.d.ts +1 -1
  229. package/utils/rules/max/max.es6.js +3 -3
  230. package/utils/rules/max/max.js +3 -3
  231. package/utils/rules/maxBin/maxBin.es6.js +2 -2
  232. package/utils/rules/maxBin/maxBin.js +2 -2
  233. package/utils/rules/maxDate/maxDate.es6.js +1 -1
  234. package/utils/rules/maxDate/maxDate.js +1 -1
  235. package/utils/rules/maxLength/maxLength.es6.js +2 -2
  236. package/utils/rules/maxLength/maxLength.js +2 -2
  237. package/utils/rules/min/min.d.ts +1 -1
  238. package/utils/rules/min/min.es6.js +3 -3
  239. package/utils/rules/min/min.js +3 -3
  240. package/utils/rules/minBin/minBin.es6.js +2 -2
  241. package/utils/rules/minBin/minBin.js +2 -2
  242. package/utils/rules/minDate/minDate.es6.js +1 -1
  243. package/utils/rules/minDate/minDate.js +1 -1
  244. package/utils/rules/minLength/minLength.es6.js +2 -2
  245. package/utils/rules/minLength/minLength.js +2 -2
  246. package/utils/rules/objectOf/objectOf.d.ts +1 -1
  247. package/utils/rules/objectOf/objectOf.es6.js +11 -1
  248. package/utils/rules/objectOf/objectOf.js +11 -1
  249. package/utils/rules/pattern/pattern.d.ts +1 -1
  250. package/utils/rules/pattern/pattern.es6.js +2 -1
  251. package/utils/rules/pattern/pattern.js +2 -1
  252. package/example/app/App/App.d.ts +0 -1
  253. package/example/app/App/index.d.ts +0 -1
  254. package/example/index.d.ts +0 -1
  255. package/example/requests/index.d.ts +0 -1
  256. package/example/requests/todo/AddTodo/AddTodo.d.ts +0 -1
  257. package/example/requests/todo/AddTodo/index.d.ts +0 -1
  258. package/example/requests/todo/DeleteTodo/DeleteTodo.d.ts +0 -1
  259. package/example/requests/todo/DeleteTodo/index.d.ts +0 -1
  260. package/example/requests/todo/EditTodo/EditTodo.d.ts +0 -1
  261. package/example/requests/todo/EditTodo/index.d.ts +0 -1
  262. package/example/requests/todo/GetTodo/GetTodo.d.ts +0 -1
  263. package/example/requests/todo/GetTodo/index.d.ts +0 -1
  264. package/example/requests/todo/GetTodos/GetTodos.d.ts +0 -1
  265. package/example/requests/todo/GetTodos/index.d.ts +0 -1
  266. package/example/requests/todo/index.d.ts +0 -5
  267. package/example/requests/todo/todos.d.ts +0 -1
  268. package/example/schemas/app/ListQueryParams/ListQueryParams.d.ts +0 -1
  269. package/example/schemas/app/ListQueryParams/index.d.ts +0 -1
  270. package/example/schemas/app/ListSchema/ListSchema.d.ts +0 -4
  271. package/example/schemas/app/ListSchema/index.d.ts +0 -1
  272. package/example/schemas/app/index.d.ts +0 -2
  273. package/example/schemas/index.d.ts +0 -2
  274. package/example/schemas/todo/TodoSchema/TodoSchema.d.ts +0 -4
  275. package/example/schemas/todo/TodoSchema/index.d.ts +0 -1
  276. package/example/schemas/todo/index.d.ts +0 -1
  277. package/example/tags/Todo/Todo.d.ts +0 -1
  278. package/example/tags/Todo/index.d.ts +0 -1
  279. package/example/tags/index.d.ts +0 -1
  280. package/hooks/useRequestPlugin/index.d.ts +0 -1
  281. package/hooks/useRequestPlugin/index.es6.js +0 -1
  282. package/hooks/useRequestPlugin/index.js +0 -9
  283. package/hooks/useRequestPlugin/useRequestPlugin.d.ts +0 -2
  284. package/hooks/useRequestPlugin/useRequestPlugin.es6.js +0 -13
  285. package/hooks/useRequestPlugin/useRequestPlugin.js +0 -17
  286. package/openApi.test.d.ts +0 -1
  287. package/plugins/main/fallback/fallback.d.ts +0 -4
  288. package/plugins/main/fallback/fallback.es6.js +0 -19
  289. package/plugins/main/fallback/fallback.js +0 -23
  290. package/plugins/main/fallback/index.d.ts +0 -1
  291. package/plugins/main/fallback/index.es6.js +0 -1
  292. package/plugins/main/fallback/index.js +0 -9
  293. package/plugins/main/request/index.d.ts +0 -1
  294. package/plugins/main/request/index.es6.js +0 -1
  295. package/plugins/main/request/index.js +0 -9
  296. package/plugins/main/request/request.d.ts +0 -4
  297. package/plugins/main/request/request.es6.js +0 -21
  298. package/plugins/main/request/request.js +0 -25
  299. package/plugins/utils/dev/dev.d.ts +0 -4
  300. package/plugins/utils/dev/dev.es6.js +0 -10
  301. package/plugins/utils/dev/index.d.ts +0 -1
  302. package/plugins/utils/dev/index.es6.js +0 -1
  303. package/plugins/utils/prod/index.d.ts +0 -1
  304. package/plugins/utils/prod/index.es6.js +0 -1
  305. package/plugins/utils/prod/prod.d.ts +0 -4
  306. package/plugins/utils/prod/prod.es6.js +0 -10
  307. package/utils/decorators/once/once.test.d.ts +0 -1
  308. package/utils/generateTypes/generateTypes.test.d.ts +0 -1
  309. package/utils/parseSearch/parseSearch.test.d.ts +0 -1
  310. package/utils/rules/any/any.d.ts +0 -1
  311. package/utils/rules/any/any.es6.js +0 -5
  312. package/utils/rules/any/any.js +0 -9
  313. /package/{utils/rules → plugins/schema}/any/index.d.ts +0 -0
  314. /package/{utils/rules → plugins/schema}/any/index.es6.js +0 -0
  315. /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 `innetjs` usage.
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:80
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 `442` for `https`.
139
- - You can use `PORT` environment variable to set it up on CI level.
140
- - [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `PORT` in `.env` file of local environment.
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 `SSL_KEY` and `SSL_CRT` environment variables to set it up on CI level.
159
- - [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `SSL_KEY` and `SSL_CRT` in `.env` file.
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,9 +582,10 @@ This section contains elements of utils.
316
582
  [← back](#index)
317
583
 
318
584
  [\<swagger>](#swagger)
319
- [\<dev>](#dev)
320
- [\<prod>](#prod)
321
- [\<dts>](#dts)
585
+ [\<env>](#env)
586
+ [\<dts>](#dts)
587
+ [\<blacklist>](#blacklist)
588
+ [\<whitelist>](#whitelist)
322
589
  [\<protection>](#protection)
323
590
 
324
591
  ---
@@ -357,39 +624,48 @@ export default (
357
624
  )
358
625
  ```
359
626
 
360
- ### \<dev>
627
+ ### \<env>
361
628
 
362
629
  [← back](#utils)
363
630
 
364
- Everything inside <dev> will work when `NODE_ENV` equals `development`.
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`.
365
636
 
366
637
  *src/app.tsx*
367
638
  ```typescript jsx
368
639
  export default (
369
640
  <server>
370
641
  <api>
371
- <dev>
642
+ <env is='dev'>
372
643
  <swagger />
373
- </dev>
644
+ </env>
374
645
  </api>
375
646
  </server>
376
647
  )
377
648
  ```
378
649
 
379
- ### \<prod>
650
+ *The `<swagger />` will work only if `NODE_ENV` equals `dev`*
380
651
 
381
- [← back](#utils)
652
+ #### of
382
653
 
383
- Everything inside <prod> will work when `NODE_ENV` equals `production`.
654
+ By default `of` equals `NODE_ENV`. You can check eny other environment variable.
384
655
 
385
656
  *src/app.tsx*
386
657
  ```typescript jsx
387
658
  export default (
388
659
  <server>
389
660
  <api>
390
- <prod>
661
+ <env
662
+ of='PORT'
663
+ is={[
664
+ '3000',
665
+ '8080',
666
+ ]}>
391
667
  <swagger />
392
- </prod>
668
+ </env>
393
669
  </api>
394
670
  </server>
395
671
  )
@@ -402,16 +678,12 @@ export default (
402
678
  Use `<dts>` element to add types generation.
403
679
  `<dts>` element MUST be placed in `<api>` element.
404
680
 
405
- `<dts>` has a required prop of `path`. This is a path of api TypeScript types file, `<dts>` generates it.
406
-
407
681
  *src/app.tsx*
408
682
  ```typescript jsx
409
683
  export default (
410
684
  <server>
411
685
  <api>
412
- <dev>
413
- <dts path='src/api.d.ts' />
414
- </dev>
686
+ <dts />
415
687
  </api>
416
688
  </server>
417
689
  )
@@ -440,29 +712,141 @@ export function DeleteTodo () {
440
712
  }
441
713
  ```
442
714
 
443
- ### \<protection>
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.
444
749
 
445
750
  [← back](#utils)
446
751
 
447
- This element adds protection page.
448
- You can use it when you want to protect your application.
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
+
449
789
  This element MUST be placed in `<api>` element.
450
790
 
451
- #### html
791
+ [← back](#utils)
452
792
 
453
- `<protection>` has a required prop of `html`.
454
- This is a `string` of HTML a user will see if they have no protection.
793
+ This element returns own content for a user IP, which is not in a list.
455
794
 
456
795
  *src/app.tsx*
457
796
  ```typescript jsx
458
- import html from './protection.html'
797
+ export default (
798
+ <server>
799
+ <api>
800
+ <whitelist>
801
+ <error />
802
+ </whitelist>
803
+ </api>
804
+ </server>
805
+ )
806
+ ```
807
+
808
+ #### ip
459
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
460
816
  export default (
461
817
  <server>
462
818
  <api>
463
- <protection
464
- html={html}
465
- />
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>
466
850
  </api>
467
851
  </server>
468
852
  )
@@ -478,15 +862,15 @@ You can use `PROTECTION` env to set default protection `value`.
478
862
 
479
863
  *src/app.tsx*
480
864
  ```typescript jsx
481
- import html from './protection.html'
482
-
483
865
  export default (
484
866
  <server>
485
867
  <api>
486
- <protection
487
- value='secret'
488
- html={html}
489
- />
868
+ <protection value='secret'>
869
+ <error
870
+ code='protection'
871
+ status='forbidden'
872
+ />
873
+ </protection>
490
874
  </api>
491
875
  </server>
492
876
  )
@@ -497,19 +881,21 @@ export default (
497
881
  This prop sets how much time protection is qualified.
498
882
 
499
883
  By default, the prop equals a year.
500
- You can use `PROTECTION_MAX_AGE` env to set default `maxAge`.
884
+ You can use `INNET_PROTECTION_MAX_AGE` env to set default `maxAge`.
501
885
 
502
886
  *src/app.tsx*
503
887
  ```typescript jsx
504
- import html from './protection.html'
505
-
506
888
  export default (
507
889
  <server>
508
890
  <api>
509
891
  <protection
510
892
  maxAge={24 * 60 * 60}
511
- html={html}
512
- />
893
+ value='secret'>
894
+ <error
895
+ code='protection'
896
+ status='forbidden'
897
+ />
898
+ </protection>
513
899
  </api>
514
900
  </server>
515
901
  )
@@ -519,19 +905,21 @@ export default (
519
905
 
520
906
  This prop sets a list of IP addresses (split by `,`) to ignore the protection.
521
907
 
522
- You can use `PROTECTED_IP` env to set default `excludeIp`.
908
+ You can use `INNET_PROTECTED_IP` env to set default `excludeIp`.
523
909
 
524
910
  *src/app.tsx*
525
911
  ```typescript jsx
526
- import html from './protection.html'
527
-
528
912
  export default (
529
913
  <server>
530
914
  <api>
531
915
  <protection
532
916
  excludeIp='0.0.0.0,127.0.0.0'
533
- html={html}
534
- />
917
+ value='secret'>
918
+ <error
919
+ code='protection'
920
+ status='forbidden'
921
+ />
922
+ </protection>
535
923
  </api>
536
924
  </server>
537
925
  )
@@ -542,19 +930,21 @@ export default (
542
930
  This prop sets a cookie field name used to store protection of a user.
543
931
 
544
932
  By default, it equals `protection`.
545
- You can use `PROTECTION_COOKIE_KEY` env to set default `cookieKey`.
933
+ You can use `INNET_PROTECTION_COOKIE_KEY` env to set default `cookieKey`.
546
934
 
547
935
  *src/app.tsx*
548
936
  ```typescript jsx
549
- import html from './protection.html'
550
-
551
937
  export default (
552
938
  <server>
553
939
  <api>
554
940
  <protection
555
941
  cookieKey='secret'
556
- html={html}
557
- />
942
+ value='secret'>
943
+ <error
944
+ code='protection'
945
+ status='forbidden'
946
+ />
947
+ </protection>
558
948
  </api>
559
949
  </server>
560
950
  )
@@ -565,19 +955,21 @@ export default (
565
955
  This prop sets a search query field name used to check protection.
566
956
 
567
957
  By default, it equals `protection`.
568
- You can use `PROTECTION_SEARCH_KEY` env to set default `searchKey`.
958
+ You can use `INNET_PROTECTION_SEARCH_KEY` env to set default `searchKey`.
569
959
 
570
960
  *src/app.tsx*
571
961
  ```typescript jsx
572
- import html from './protection.html'
573
-
574
962
  export default (
575
963
  <server>
576
964
  <api>
577
965
  <protection
578
966
  searchKey='secret'
579
- html={html}
580
- />
967
+ value='secret'>
968
+ <error
969
+ code='protection'
970
+ status='forbidden'
971
+ />
972
+ </protection>
581
973
  </api>
582
974
  </server>
583
975
  )
@@ -1151,6 +1543,7 @@ This element MUST be placed inside `<endpoint>`.
1151
1543
  It defines request body for the endpoint.
1152
1544
  `@innet/server` formats and validate the value automatically (real-time).
1153
1545
 
1546
+ *src/app.tsx*
1154
1547
  ```typescript jsx
1155
1548
  return (
1156
1549
  <server>
@@ -1177,25 +1570,283 @@ return (
1177
1570
  )
1178
1571
  ```
1179
1572
 
1180
- ### \<response>
1181
-
1182
- [← back](#endpoints)
1183
-
1184
- This element MUST be placed inside `<endpoint>`.
1185
- It defines response body for the endpoint.
1186
-
1187
- ## Primitive Data
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
1188
1831
 
1189
- [← back](#index)
1832
+ A description of the `null`.
1190
1833
 
1191
- [\<null>](#null)
1192
- [\<boolean>](#boolean)
1193
- [\<string>](#string)
1194
- [\<number>](#number)
1195
- [\<integer>](#integer)
1196
- [\<date>](#date)
1197
- [\<uuid>](#uuid)
1198
- [\<binary>](#binary)
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
+ ```
1199
1850
 
1200
1851
  ### \<boolean>
1201
1852
 
@@ -2477,7 +3128,9 @@ export default (
2477
3128
  <api>
2478
3129
  <endpoint method='post' path='/users'>
2479
3130
  <body>
2480
- <object />
3131
+ <object>
3132
+ <string />
3133
+ </object>
2481
3134
  </body>
2482
3135
  </endpoint>
2483
3136
  </api>
@@ -2538,9 +3191,9 @@ export default (
2538
3191
  <api>
2539
3192
  <endpoint method='post' path='/users'>
2540
3193
  <body>
2541
- <object
2542
- description='The object of a user'
2543
- />
3194
+ <object
3195
+ description='The object of a user'
3196
+ />
2544
3197
  </body>
2545
3198
  </endpoint>
2546
3199
  </api>
@@ -2556,7 +3209,7 @@ The element MUST be placed inside [\<object>](#object).
2556
3209
  It defines a `field` of an `object` value for a parent element.
2557
3210
  `@innet/server` formats and validate the value automatically (real-time).
2558
3211
 
2559
- `key` is REQUIRED prop of `<field>`, it defines a field name of the `<object>`.
3212
+ `key` is REQUIRED prop of `<field>`, it defines a field name of the [\<object>](#object).
2560
3213
 
2561
3214
  *src/app.tsx*
2562
3215
  ```typescript jsx
@@ -2600,116 +3253,46 @@ export default (
2600
3253
  )
2601
3254
  ```
2602
3255
 
2603
- ## Run-Time
2604
-
2605
- Next elements relate to run-time action.
2606
- This action calls on user request.
2607
-
2608
- [← back](#index)
2609
-
2610
- Parent
2611
- [\<fallback>](#fallback)
2612
- [\<request>](#request)
2613
-
2614
- Children
2615
- [\<success>](#success)
2616
- [\<error>](#error)
2617
- [\<proxy>](#proxy)
2618
- [\<redirect>](#redirect)
2619
- [\<cms>](#cms)
2620
- [\<file>](#file)
2621
- [\<header>](#header)
2622
- [\<cookie>](#cookie)
2623
-
2624
- ---
2625
-
2626
- ### \<fallback>
2627
-
2628
- [← back](#run-time)
2629
-
2630
- By default, `<api>` server returns 404 with empty body.
2631
- [\<fallback>](#fallback) element defines default server response.
2632
- This element MUST be placed in `<api>`.
2633
- You MUST use one [\<fallback>](#fallback) per `<api>`.
2634
- Can contain elements available inside [\<request>](#request).
2635
-
2636
- *src/app.tsx*
2637
- ```typescript jsx
2638
- export default (
2639
- <server>
2640
- <api>
2641
- <fallback>
2642
- <error
2643
- code='unknownEndpoint'
2644
- />
2645
- </fallback>
2646
- </api>
2647
- </server>
2648
- )
2649
- ```
2650
-
2651
- If you open the application on any URL except for `/`, you can see the next response.
2652
-
2653
- ```json
2654
- {
2655
- "error": "unknownEndpoint"
2656
- }
2657
- ```
2658
-
2659
- The next elements are placed in [\<request>](#request) or [\<fallback>](#fallback)
2660
-
2661
- ### \<request>
2662
-
2663
- [← back](#run-time)
3256
+ #### deprecated
2664
3257
 
2665
- This element MUST be placed in `<endpoint>` element.
2666
- It defines run-time call handler for the endpoint.
3258
+ You can deprecate a field.
2667
3259
 
2668
3260
  *src/app.tsx*
2669
3261
  ```typescript jsx
2670
3262
  export default (
2671
3263
  <server>
2672
3264
  <api>
2673
- <endpoint method='get' path='/partners'>
2674
- <request>
2675
- <success>
2676
- {{partners: []}}
2677
- </success>
2678
- </request>
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>
2679
3273
  </endpoint>
2680
3274
  </api>
2681
3275
  </server>
2682
3276
  )
2683
3277
  ```
2684
3278
 
2685
- You can place a component inside it.
2686
- The component will run when the endpoint will be triggered.
3279
+ ## Run-Time
2687
3280
 
2688
- *src/app.tsx*
2689
- ```typescript jsx
2690
- import { GetPartners } from './GetPartners'
3281
+ Next elements relate to run-time action.
3282
+ This action calls on user request.
2691
3283
 
2692
- export default (
2693
- <server>
2694
- <api>
2695
- <endpoint method='get' path='/partners'>
2696
- <request>
2697
- <GetPartners />
2698
- </request>
2699
- </endpoint>
2700
- </api>
2701
- </server>
2702
- )
2703
- ```
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)
2704
3294
 
2705
- *src/GetPartners.tsx*
2706
- ```typescript jsx
2707
- export const GetPartners = () => (
2708
- <success>
2709
- {{partners: []}}
2710
- </success>
2711
- )
2712
- ```
3295
+ ---
2713
3296
 
2714
3297
  ### \<success>
2715
3298
 
@@ -2721,11 +3304,9 @@ This is a base element to return a success data.
2721
3304
  ```typescript jsx
2722
3305
  export default (
2723
3306
  <server>
2724
- <api>
2725
- <fallback>
2726
- <success />
2727
- </fallback>
2728
- </api>
3307
+ <return>
3308
+ <success />
3309
+ </return>
2729
3310
  </server>
2730
3311
  )
2731
3312
  ```
@@ -2740,13 +3321,11 @@ const data = {...}
2740
3321
 
2741
3322
  export default (
2742
3323
  <server>
2743
- <api>
2744
- <fallback>
2745
- <success>
2746
- {data}
2747
- </success>
2748
- </fallback>
2749
- </api>
3324
+ <return>
3325
+ <success>
3326
+ {data}
3327
+ </success>
3328
+ </return>
2750
3329
  </server>
2751
3330
  )
2752
3331
  ```
@@ -2763,13 +3342,11 @@ const data = {...}
2763
3342
 
2764
3343
  export default (
2765
3344
  <server>
2766
- <api>
2767
- <fallback>
2768
- <success status='created'>
2769
- {data}
2770
- </success>
2771
- </fallback>
2772
- </api>
3345
+ <return>
3346
+ <success status='created'>
3347
+ {data}
3348
+ </success>
3349
+ </return>
2773
3350
  </server>
2774
3351
  )
2775
3352
  ```
@@ -2784,13 +3361,29 @@ const data = {...}
2784
3361
 
2785
3362
  export default (
2786
3363
  <server>
2787
- <api>
2788
- <fallback>
2789
- <success status={201}>
2790
- {data}
2791
- </success>
2792
- </fallback>
2793
- </api>
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>
2794
3387
  </server>
2795
3388
  )
2796
3389
  ```
@@ -2800,17 +3393,15 @@ export default (
2800
3393
  [← back](#run-time)
2801
3394
 
2802
3395
  Returns an error.
2803
- This element MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
3396
+ This element MUST be placed in [\<return>](#return).
2804
3397
 
2805
3398
  *src/app.tsx*
2806
3399
  ```typescript jsx
2807
3400
  export default (
2808
3401
  <server>
2809
- <api>
2810
- <fallback>
2811
- <error />
2812
- </fallback>
2813
- </api>
3402
+ <return>
3403
+ <error />
3404
+ </return>
2814
3405
  </server>
2815
3406
  )
2816
3407
  ```
@@ -2823,13 +3414,11 @@ const data = {...}
2823
3414
 
2824
3415
  export default (
2825
3416
  <server>
2826
- <api>
2827
- <fallback>
2828
- <error>
2829
- {data}
2830
- </error>
2831
- </fallback>
2832
- </api>
3417
+ <return>
3418
+ <error>
3419
+ {data}
3420
+ </error>
3421
+ </return>
2833
3422
  </server>
2834
3423
  )
2835
3424
  ```
@@ -2845,13 +3434,11 @@ const data = {
2845
3434
 
2846
3435
  export default (
2847
3436
  <server>
2848
- <api>
2849
- <fallback>
2850
- <error status='notFound'>
2851
- {data}
2852
- </error>
2853
- </fallback>
2854
- </api>
3437
+ <return>
3438
+ <error status='notFound'>
3439
+ {data}
3440
+ </error>
3441
+ </return>
2855
3442
  </server>
2856
3443
  )
2857
3444
  ```
@@ -2866,13 +3453,11 @@ const data = {
2866
3453
 
2867
3454
  export default (
2868
3455
  <server>
2869
- <api>
2870
- <fallback>
2871
- <error status={404}>
2872
- {data}
2873
- </error>
2874
- </fallback>
2875
- </api>
3456
+ <return>
3457
+ <error status={404}>
3458
+ {data}
3459
+ </error>
3460
+ </return>
2876
3461
  </server>
2877
3462
  )
2878
3463
  ```
@@ -2900,15 +3485,13 @@ const data = {
2900
3485
 
2901
3486
  export default (
2902
3487
  <server>
2903
- <api>
2904
- <fallback>
2905
- <error
2906
- code='noUser'
2907
- status='notFound'>
2908
- {data}
2909
- </error>
2910
- </fallback>
2911
- </api>
3488
+ <return>
3489
+ <error
3490
+ code='noUser'
3491
+ status='notFound'>
3492
+ {data}
3493
+ </error>
3494
+ </return>
2912
3495
  </server>
2913
3496
  )
2914
3497
  ```
@@ -2936,7 +3519,7 @@ There are some default errors:
2936
3519
 
2937
3520
  [← back](#run-time)
2938
3521
 
2939
- MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
3522
+ MUST be placed in [\<return>](#return).
2940
3523
 
2941
3524
  You can easy proxy endpoints to another server/service.
2942
3525
 
@@ -2948,14 +3531,14 @@ export default (
2948
3531
  <endpoint
2949
3532
  path='/test'
2950
3533
  method='get'>
2951
- <request>
3534
+ <return>
2952
3535
  <proxy to='https://...' />
2953
- </request>
3536
+ </return>
2954
3537
  </endpoint>
2955
- <fallback>
2956
- <proxy to='https://...' />
2957
- </fallback>
2958
3538
  </api>
3539
+ <return>
3540
+ <proxy to='https://...' />
3541
+ </return>
2959
3542
  </server>
2960
3543
  )
2961
3544
  ```
@@ -2964,7 +3547,7 @@ export default (
2964
3547
 
2965
3548
  [← back](#run-time)
2966
3549
 
2967
- MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
3550
+ MUST be placed in [\<return>](#return).
2968
3551
 
2969
3552
  You can redirect users to another resource. It adds `Cache-Control` header by default.
2970
3553
 
@@ -2976,14 +3559,14 @@ export default (
2976
3559
  <endpoint
2977
3560
  path='/test'
2978
3561
  method='get'>
2979
- <request>
3562
+ <return>
2980
3563
  <redirect to='https://...' />
2981
- </request>
3564
+ </return>
2982
3565
  </endpoint>
2983
- <fallback>
2984
- <redirect to='https://...' />
2985
- </fallback>
2986
3566
  </api>
3567
+ <return>
3568
+ <redirect to='https://...' />
3569
+ </return>
2987
3570
  </server>
2988
3571
  )
2989
3572
  ```
@@ -3001,20 +3584,20 @@ export default (
3001
3584
  <endpoint
3002
3585
  path='/test'
3003
3586
  method='get'>
3004
- <request>
3587
+ <return>
3005
3588
  <redirect
3006
3589
  status='found'
3007
3590
  to='https://...'
3008
3591
  />
3009
- </request>
3592
+ </return>
3010
3593
  </endpoint>
3011
- <fallback>
3012
- <redirect
3013
- status={303}
3014
- to='https://...'
3015
- />
3016
- </fallback>
3017
3594
  </api>
3595
+ <return>
3596
+ <redirect
3597
+ status={303}
3598
+ to='https://...'
3599
+ />
3600
+ </return>
3018
3601
  </server>
3019
3602
  )
3020
3603
  ```
@@ -3023,7 +3606,7 @@ export default (
3023
3606
 
3024
3607
  [← back](#run-time)
3025
3608
 
3026
- MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
3609
+ MUST be placed in [\<return>](#return).
3027
3610
 
3028
3611
  `<cms>` helps to return files from a folder by path. It checks files run-time on the server.
3029
3612
 
@@ -3031,18 +3614,16 @@ MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
3031
3614
  ```typescript jsx
3032
3615
  export default (
3033
3616
  <server>
3034
- <api>
3035
- <fallback>
3036
- <cms />
3037
- </fallback>
3038
- </api>
3617
+ <return>
3618
+ <cms />
3619
+ </return>
3039
3620
  </server>
3040
3621
  )
3041
3622
  ```
3042
3623
 
3043
3624
  #### dir
3044
3625
 
3045
- By default, it looks at project folder.
3626
+ By default, it equals `INNET_CMS_DIR` node env variable or the project folder.
3046
3627
  If you try the previous example on [http://localhost/package.json](http://localhost/package.json)
3047
3628
  you get the project `package.json` file.
3048
3629
 
@@ -3052,11 +3633,9 @@ You can change root folder by `dir` property.
3052
3633
  ```typescript jsx
3053
3634
  export default (
3054
3635
  <server>
3055
- <api>
3056
- <fallback>
3057
- <cms dir='src' />
3058
- </fallback>
3059
- </api>
3636
+ <return>
3637
+ <cms dir='src' />
3638
+ </return>
3060
3639
  </server>
3061
3640
  )
3062
3641
  ```
@@ -3067,15 +3646,16 @@ you get the index file in `src` folder.
3067
3646
  #### prefix
3068
3647
 
3069
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 `/`.
3070
3650
 
3071
3651
  *src/app.tsx*
3072
3652
  ```typescript jsx
3073
3653
  export default (
3074
3654
  <server>
3075
3655
  <api prefix='/src'>
3076
- <fallback>
3656
+ <return>
3077
3657
  <cms />
3078
- </fallback>
3658
+ </return>
3079
3659
  </api>
3080
3660
  </server>
3081
3661
  )
@@ -3091,9 +3671,9 @@ You can reduce the path for matching by prefix property of `<cms>`.
3091
3671
  export default (
3092
3672
  <server>
3093
3673
  <api prefix='/api'>
3094
- <fallback>
3674
+ <return>
3095
3675
  <cms prefix='/api' />
3096
- </fallback>
3676
+ </return>
3097
3677
  </api>
3098
3678
  </server>
3099
3679
  )
@@ -3109,13 +3689,11 @@ You can handle if a file was not found by children elements of `<cms>`.
3109
3689
  ```typescript jsx
3110
3690
  export default (
3111
3691
  <server>
3112
- <api prefix='/src'>
3113
- <fallback>
3114
- <cms>
3115
- <error status={404} />
3116
- </cms>
3117
- </fallback>
3118
- </api>
3692
+ <return>
3693
+ <cms>
3694
+ <error status={404} />
3695
+ </cms>
3696
+ </return>
3119
3697
  </server>
3120
3698
  )
3121
3699
  ```
@@ -3124,7 +3702,7 @@ export default (
3124
3702
 
3125
3703
  [← back](#run-time)
3126
3704
 
3127
- It returns a file. MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
3705
+ It returns a file. MUST be placed in [\<return>](#return).
3128
3706
 
3129
3707
  It adds `Content-Length` and `Content-Type` automatically.
3130
3708
 
@@ -3134,13 +3712,9 @@ It has a REQUIRED property of `path`.
3134
3712
  ```typescript jsx
3135
3713
  export default (
3136
3714
  <server>
3137
- <api>
3138
- <fallback>
3139
- <file
3140
- path='package.json'
3141
- />
3142
- </fallback>
3143
- </api>
3715
+ <return>
3716
+ <file path='package.json' />
3717
+ </return>
3144
3718
  </server>
3145
3719
  )
3146
3720
  ```
@@ -3155,20 +3729,18 @@ You can handle if a file was not found by children elements of `<file>`.
3155
3729
  ```typescript jsx
3156
3730
  export default (
3157
3731
  <server>
3158
- <api prefix='/src'>
3159
- <fallback>
3160
- <file path='file_is_not_exist.txt'>
3161
- <error status={404} />
3162
- </file>
3163
- </fallback>
3164
- </api>
3732
+ <return>
3733
+ <file path='file_is_not_exist.txt'>
3734
+ <error status={404} />
3735
+ </file>
3736
+ </return>
3165
3737
  </server>
3166
3738
  )
3167
3739
  ```
3168
3740
 
3169
3741
  ### \<header>
3170
3742
 
3171
- MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
3743
+ MUST be placed in [\<return>](#return).
3172
3744
 
3173
3745
  [← back](#run-time)
3174
3746
 
@@ -3178,22 +3750,20 @@ You can add an HTTP header into response by `<header>` element.
3178
3750
  ```typescript jsx
3179
3751
  export default (
3180
3752
  <server>
3181
- <api prefix='/src'>
3182
- <fallback>
3183
- <header
3184
- key='Cache-Control'
3185
- value='no-cache, no-store, must-revalidate'
3186
- />
3187
- <success />
3188
- </fallback>
3189
- </api>
3753
+ <return>
3754
+ <header
3755
+ key='Cache-Control'
3756
+ value='no-cache, no-store, must-revalidate'
3757
+ />
3758
+ <success />
3759
+ </return>
3190
3760
  </server>
3191
3761
  )
3192
3762
  ```
3193
3763
 
3194
3764
  ### \<cookie>
3195
3765
 
3196
- MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
3766
+ MUST be placed in [\<return>](#return).
3197
3767
 
3198
3768
  [← back](#run-time)
3199
3769
 
@@ -3203,18 +3773,16 @@ You can add/remove a cookie into response by `<cookie>` element.
3203
3773
  ```typescript jsx
3204
3774
  export default (
3205
3775
  <server>
3206
- <api prefix='/src'>
3207
- <fallback>
3208
- <cookie
3209
- key='token'
3210
- value='...'
3211
- />
3212
- <cookie
3213
- key='removedCookie'
3214
- />
3215
- <success />
3216
- </fallback>
3217
- </api>
3776
+ <return>
3777
+ <cookie
3778
+ key='token'
3779
+ value='...'
3780
+ />
3781
+ <cookie
3782
+ key='removedCookie'
3783
+ />
3784
+ <success />
3785
+ </return>
3218
3786
  </server>
3219
3787
  )
3220
3788
  ```
@@ -3228,16 +3796,14 @@ By default, no domain is set, and most clients will consider the cookie to apply
3228
3796
  ```typescript jsx
3229
3797
  export default (
3230
3798
  <server>
3231
- <api prefix='/src'>
3232
- <fallback>
3233
- <cookie
3234
- domain='.example.com'
3235
- key='token'
3236
- value='...'
3237
- />
3238
- <success />
3239
- </fallback>
3240
- </api>
3799
+ <return>
3800
+ <cookie
3801
+ domain='.example.com'
3802
+ key='token'
3803
+ value='...'
3804
+ />
3805
+ <success />
3806
+ </return>
3241
3807
  </server>
3242
3808
  )
3243
3809
  ```
@@ -3256,16 +3822,14 @@ Note the [cookie storage model specification](https://datatracker.ietf.org/doc/h
3256
3822
  ```typescript jsx
3257
3823
  export default (
3258
3824
  <server>
3259
- <api prefix='/src'>
3260
- <fallback>
3261
- <cookie
3262
- expires={new Date('2050-01-01')}
3263
- key='token'
3264
- value='...'
3265
- />
3266
- <success />
3267
- </fallback>
3268
- </api>
3825
+ <return>
3826
+ <cookie
3827
+ expires={new Date('2050-01-01')}
3828
+ key='token'
3829
+ value='...'
3830
+ />
3831
+ <success />
3832
+ </return>
3269
3833
  </server>
3270
3834
  )
3271
3835
  ```
@@ -3279,16 +3843,14 @@ Note be careful when setting this to true, as compliant clients will not allow c
3279
3843
  ```typescript jsx
3280
3844
  export default (
3281
3845
  <server>
3282
- <api prefix='/src'>
3283
- <fallback>
3284
- <cookie
3285
- httpOnly
3286
- key='token'
3287
- value='...'
3288
- />
3289
- <success />
3290
- </fallback>
3291
- </api>
3846
+ <return>
3847
+ <cookie
3848
+ httpOnly
3849
+ key='token'
3850
+ value='...'
3851
+ />
3852
+ <success />
3853
+ </return>
3292
3854
  </server>
3293
3855
  )
3294
3856
  ```
@@ -3302,17 +3864,15 @@ Note the [cookie storage model specification](https://datatracker.ietf.org/doc/h
3302
3864
  ```typescript jsx
3303
3865
  export default (
3304
3866
  <server>
3305
- <api prefix='/src'>
3306
- <fallback>
3307
- <cookie
3308
- httpOnly
3309
- maxAge={9999}
3310
- key='token'
3311
- value='...'
3312
- />
3313
- <success />
3314
- </fallback>
3315
- </api>
3867
+ <return>
3868
+ <cookie
3869
+ httpOnly
3870
+ maxAge={9999}
3871
+ key='token'
3872
+ value='...'
3873
+ />
3874
+ <success />
3875
+ </return>
3316
3876
  </server>
3317
3877
  )
3318
3878
  ```
@@ -3326,18 +3886,16 @@ By default, the path is considered the “default path”.
3326
3886
  ```typescript jsx
3327
3887
  export default (
3328
3888
  <server>
3329
- <api prefix='/src'>
3330
- <fallback>
3331
- <cookie
3332
- httpOnly
3333
- maxAge={9999}
3334
- path='/src'
3335
- key='token'
3336
- value='...'
3337
- />
3338
- <success />
3339
- </fallback>
3340
- </api>
3889
+ <return>
3890
+ <cookie
3891
+ httpOnly
3892
+ maxAge={9999}
3893
+ path='/src'
3894
+ key='token'
3895
+ value='...'
3896
+ />
3897
+ <success />
3898
+ </return>
3341
3899
  </server>
3342
3900
  )
3343
3901
  ```
@@ -3356,18 +3914,16 @@ note This is an attribute that has not yet been fully standardized, and may chan
3356
3914
  ```typescript jsx
3357
3915
  export default (
3358
3916
  <server>
3359
- <api prefix='/src'>
3360
- <fallback>
3361
- <cookie
3362
- httpOnly
3363
- priority='high'
3364
- path='/src'
3365
- key='token'
3366
- value='...'
3367
- />
3368
- <success />
3369
- </fallback>
3370
- </api>
3917
+ <return>
3918
+ <cookie
3919
+ httpOnly
3920
+ priority='high'
3921
+ path='/src'
3922
+ key='token'
3923
+ value='...'
3924
+ />
3925
+ <success />
3926
+ </return>
3371
3927
  </server>
3372
3928
  )
3373
3929
  ```
@@ -3389,19 +3945,17 @@ This also means many clients may ignore this attribute until they understand it.
3389
3945
  ```typescript jsx
3390
3946
  export default (
3391
3947
  <server>
3392
- <api prefix='/src'>
3393
- <fallback>
3394
- <cookie
3395
- httpOnly
3396
- sameSite
3397
- priority='high'
3398
- path='/src'
3399
- key='token'
3400
- value='...'
3401
- />
3402
- <success />
3403
- </fallback>
3404
- </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>
3405
3959
  </server>
3406
3960
  )
3407
3961
  ```
@@ -3418,17 +3972,15 @@ Note be careful when setting this to true, as compliant clients will not send th
3418
3972
  ```typescript jsx
3419
3973
  export default (
3420
3974
  <server>
3421
- <api prefix='/src'>
3422
- <fallback>
3423
- <cookie
3424
- httpOnly
3425
- secure
3426
- key='token'
3427
- value='...'
3428
- />
3429
- <success />
3430
- </fallback>
3431
- </api>
3975
+ <return>
3976
+ <cookie
3977
+ httpOnly
3978
+ secure
3979
+ key='token'
3980
+ value='...'
3981
+ />
3982
+ <success />
3983
+ </return>
3432
3984
  </server>
3433
3985
  )
3434
3986
  ```
@@ -3461,14 +4013,12 @@ import { SetToken } from './SetToken'
3461
4013
 
3462
4014
  export default (
3463
4015
  <server>
3464
- <api prefix='/src'>
3465
- <fallback>
3466
- <SetToken
3467
- value='...'
3468
- />
3469
- <success />
3470
- </fallback>
3471
- </api>
4016
+ <return>
4017
+ <SetToken
4018
+ value='...'
4019
+ />
4020
+ <success />
4021
+ </return>
3472
4022
  </server>
3473
4023
  )
3474
4024
  ```
@@ -3493,10 +4043,12 @@ Real-time
3493
4043
  [useClientIp](#useclientip)
3494
4044
 
3495
4045
  Server start
3496
- [useRequestPlugin](#userequestplugin)
4046
+ [useServerPlugin](#useserverplugin)
3497
4047
 
3498
4048
  Both
3499
4049
  [useServer](#useserver)
4050
+ [usePort](#useport)
4051
+ [useIsServerHttps](#useisserverhttps)
3500
4052
  [useComponentName](#usecomponentname)
3501
4053
 
3502
4054
  ---
@@ -3505,7 +4057,7 @@ Both
3505
4057
 
3506
4058
  [← back](#hooks)
3507
4059
 
3508
- This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
4060
+ This hook MUST be used in a component placed in [\<return>](#return).
3509
4061
  This hook returns current request instance.
3510
4062
 
3511
4063
  *src/Component.tsx*
@@ -3526,7 +4078,7 @@ export function Component () {
3526
4078
 
3527
4079
  [← back](#hooks)
3528
4080
 
3529
- This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
4081
+ This hook MUST be used in a component placed in [\<return>](#return).
3530
4082
  This hook returns current response instance.
3531
4083
 
3532
4084
  *src/Component.tsx*
@@ -3547,7 +4099,7 @@ export function Component () {
3547
4099
 
3548
4100
  [← back](#hooks)
3549
4101
 
3550
- This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
4102
+ This hook MUST be used in a component placed in [\<return>](#return).
3551
4103
  This hook returns current request headers object.
3552
4104
 
3553
4105
  *src/Component.tsx*
@@ -3566,7 +4118,7 @@ export function Component () {
3566
4118
 
3567
4119
  [← back](#hooks)
3568
4120
 
3569
- This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
4121
+ This hook MUST be used in a component placed in [\<return>](#return).
3570
4122
  This hook returns current request cookies object.
3571
4123
 
3572
4124
  *src/Component.tsx*
@@ -3585,7 +4137,7 @@ export function Component () {
3585
4137
 
3586
4138
  [← back](#hooks)
3587
4139
 
3588
- This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
4140
+ This hook MUST be used in a component placed in [\<return>](#return).
3589
4141
  This hook returns current request URL path as a `string`.
3590
4142
 
3591
4143
  *src/Component.tsx*
@@ -3604,7 +4156,7 @@ export function Component () {
3604
4156
 
3605
4157
  [← back](#hooks)
3606
4158
 
3607
- This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
4159
+ This hook MUST be used in a component placed in [\<return>](#return).
3608
4160
  This hook returns an object of URL params you set by [\<param>](#param).
3609
4161
 
3610
4162
  *src/Component.tsx*
@@ -3622,7 +4174,7 @@ export function Component () {
3622
4174
 
3623
4175
  [← back](#hooks)
3624
4176
 
3625
- This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
4177
+ This hook MUST be used in a component placed in [\<return>](#return).
3626
4178
  This hook returns an object of URL query params.
3627
4179
 
3628
4180
  *src/Component.tsx*
@@ -3640,7 +4192,7 @@ export function Component () {
3640
4192
 
3641
4193
  [← back](#hooks)
3642
4194
 
3643
- This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
4195
+ This hook MUST be used in a component placed in [\<return>](#return).
3644
4196
  This hook returns current request body.
3645
4197
 
3646
4198
  *src/Component.tsx*
@@ -3659,7 +4211,7 @@ export function Component () {
3659
4211
  [← back](#hooks)
3660
4212
 
3661
4213
  This hook returns request user IP.
3662
- This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
4214
+ This hook MUST be used in a component placed in [\<return>](#return).
3663
4215
 
3664
4216
  *src/Component.tsx*
3665
4217
  ```typescript jsx
@@ -3672,7 +4224,7 @@ export function Component () {
3672
4224
  }
3673
4225
  ```
3674
4226
 
3675
- ### useRequestPlugin
4227
+ ### useServerPlugin
3676
4228
 
3677
4229
  [← back](#hooks)
3678
4230
 
@@ -3680,25 +4232,24 @@ This hook adds a request plugin function.
3680
4232
  The function runs before check endpoints.
3681
4233
  If the function returns `true` the request handling stops, and you get full control over the request.
3682
4234
 
3683
- This hook MUST be used in a component placed in [\<api>](#api).
4235
+ This hook MUST be used in a component placed in [\<server>](#server).
3684
4236
 
3685
4237
  *src/SecretEndpoint.tsx*
3686
4238
  ```typescript jsx
3687
- import { useRequestPlugin } from '@innet/sever'
4239
+ import { useRequestPlugin, useAction } from '@innet/sever'
3688
4240
 
3689
4241
  export function SecretEndpoint () {
3690
- useRequestPlugin((req, res) => {
3691
- if (req.url.startsWith('/secret-endpoint')) {
3692
- res.statusCode = 200
3693
- res.write('A secret message')
3694
- res.end()
3695
- return true
4242
+ useServerPlugin(() => {
4243
+ const action = useAction()
4244
+
4245
+ if (action.path.startsWith('/secret-endpoint')) {
4246
+ return <success>A secret message</success>
3696
4247
  }
3697
4248
  })
3698
4249
  }
3699
4250
  ```
3700
4251
 
3701
- Then use the plugin in [\<api>](#api).
4252
+ Then use the plugin in [\<server>](#server) or [\<api>](#api).
3702
4253
 
3703
4254
  *src/app.tsx*
3704
4255
  ```typescript jsx
@@ -3706,12 +4257,10 @@ import { SecretEndpoint } from './SecretEndpoint'
3706
4257
 
3707
4258
  export default (
3708
4259
  <server>
3709
- <api>
3710
- <fallback>
3711
- <error />
3712
- </fallback>
3713
- <SecretEndpoint />
3714
- </api>
4260
+ <SecretEndpoint />
4261
+ <return>
4262
+ <error />
4263
+ </return>
3715
4264
  </server>
3716
4265
  )
3717
4266
  ```
@@ -3739,6 +4288,53 @@ export function Component () {
3739
4288
  }
3740
4289
  ```
3741
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
+
3742
4338
  ### useComponentName
3743
4339
 
3744
4340
  [← back](#hooks)