@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.
Files changed (322) hide show
  1. package/README.md +1200 -440
  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 +27 -14
  5. package/handler/handler.es6.js +17 -11
  6. package/handler/handler.js +17 -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/useClientIp/useClientIp.es6.js +4 -10
  15. package/hooks/useClientIp/useClientIp.js +4 -10
  16. package/hooks/useEndpoint/useEndpoint.d.ts +1 -1
  17. package/hooks/useEndpoint/useEndpoint.es6.js +3 -1
  18. package/hooks/useEndpoint/useEndpoint.js +3 -1
  19. package/hooks/useIsServerHttps/index.d.ts +1 -0
  20. package/hooks/useIsServerHttps/index.es6.js +1 -0
  21. package/hooks/useIsServerHttps/index.js +10 -0
  22. package/hooks/useIsServerHttps/useIsServerHttps.d.ts +3 -0
  23. package/hooks/useIsServerHttps/useIsServerHttps.es6.js +14 -0
  24. package/hooks/useIsServerHttps/useIsServerHttps.js +19 -0
  25. package/hooks/useNewSchema/useNewSchema.es6.js +1 -1
  26. package/hooks/useNewSchema/useNewSchema.js +1 -1
  27. package/hooks/useObjectSchemaContext/index.d.ts +1 -0
  28. package/hooks/useObjectSchemaContext/index.es6.js +1 -0
  29. package/hooks/useObjectSchemaContext/index.js +10 -0
  30. package/hooks/useObjectSchemaContext/useObjectSchemaContext.d.ts +3 -0
  31. package/hooks/useObjectSchemaContext/useObjectSchemaContext.es6.js +14 -0
  32. package/hooks/useObjectSchemaContext/useObjectSchemaContext.js +19 -0
  33. package/hooks/useRequest/index.es6.js +1 -1
  34. package/hooks/useRequest/index.js +0 -1
  35. package/hooks/useRequest/useRequest.d.ts +1 -4
  36. package/hooks/useRequest/useRequest.es6.js +4 -4
  37. package/hooks/useRequest/useRequest.js +3 -4
  38. package/hooks/useRequestHandler/index.d.ts +1 -0
  39. package/hooks/useRequestHandler/index.es6.js +1 -0
  40. package/hooks/useRequestHandler/index.js +10 -0
  41. package/hooks/useRequestHandler/useRequestHandler.d.ts +4 -0
  42. package/hooks/useRequestHandler/useRequestHandler.es6.js +14 -0
  43. package/hooks/useRequestHandler/useRequestHandler.js +19 -0
  44. package/hooks/useResponse/index.es6.js +1 -1
  45. package/hooks/useResponse/index.js +0 -1
  46. package/hooks/useResponse/useResponse.d.ts +1 -4
  47. package/hooks/useResponse/useResponse.es6.js +4 -4
  48. package/hooks/useResponse/useResponse.js +3 -4
  49. package/hooks/useSchemaType/useSchemaType.d.ts +3 -2
  50. package/hooks/useSchemaType/useSchemaType.es6.js +5 -6
  51. package/hooks/useSchemaType/useSchemaType.js +5 -6
  52. package/hooks/useServer/useServer.d.ts +2 -1
  53. package/hooks/useServer/useServer.es6.js +3 -1
  54. package/hooks/useServer/useServer.js +3 -1
  55. package/hooks/useServerPlugin/index.d.ts +1 -0
  56. package/hooks/useServerPlugin/index.es6.js +1 -0
  57. package/hooks/useServerPlugin/index.js +9 -0
  58. package/hooks/useServerPlugin/useServerPlugin.d.ts +2 -0
  59. package/hooks/useServerPlugin/useServerPlugin.es6.js +13 -0
  60. package/hooks/useServerPlugin/useServerPlugin.js +17 -0
  61. package/hooks/useServerPlugins/index.d.ts +1 -0
  62. package/hooks/useServerPlugins/index.es6.js +1 -0
  63. package/hooks/useServerPlugins/index.js +10 -0
  64. package/hooks/useServerPlugins/useServerPlugins.d.ts +4 -0
  65. package/hooks/useServerPlugins/useServerPlugins.es6.js +14 -0
  66. package/hooks/useServerPlugins/useServerPlugins.js +19 -0
  67. package/hooks/useServerPort/index.d.ts +1 -0
  68. package/hooks/useServerPort/index.es6.js +1 -0
  69. package/hooks/useServerPort/index.js +10 -0
  70. package/hooks/useServerPort/useServerPort.d.ts +3 -0
  71. package/hooks/useServerPort/useServerPort.es6.js +14 -0
  72. package/hooks/useServerPort/useServerPort.js +19 -0
  73. package/index.es6.js +17 -9
  74. package/index.js +33 -14
  75. package/package.json +2 -3
  76. package/plugins/main/api/api.d.ts +11 -8
  77. package/plugins/main/api/api.es6.js +55 -56
  78. package/plugins/main/api/api.js +54 -55
  79. package/plugins/main/body/body.d.ts +1 -0
  80. package/plugins/main/contact/contact.d.ts +2 -2
  81. package/plugins/main/endpoint/endpoint.d.ts +16 -15
  82. package/plugins/main/endpoint/endpoint.es6.js +8 -6
  83. package/plugins/main/endpoint/endpoint.js +7 -5
  84. package/plugins/main/host/host.d.ts +5 -5
  85. package/plugins/main/index.d.ts +2 -2
  86. package/plugins/main/index.es6.js +2 -2
  87. package/plugins/main/index.js +2 -2
  88. package/plugins/main/license/license.d.ts +5 -5
  89. package/plugins/main/param/param.d.ts +12 -11
  90. package/plugins/main/param/param.es6.js +6 -6
  91. package/plugins/main/param/param.js +5 -5
  92. package/plugins/main/preset/index.d.ts +1 -0
  93. package/plugins/main/preset/index.es6.js +1 -0
  94. package/plugins/{utils/prod → main/preset}/index.js +2 -2
  95. package/plugins/main/preset/preset.d.ts +3 -0
  96. package/plugins/main/preset/preset.es6.js +13 -0
  97. package/plugins/{utils/dev/dev.js → main/preset/preset.js} +9 -6
  98. package/plugins/main/response/index.es6.js +1 -1
  99. package/plugins/main/response/index.js +1 -0
  100. package/plugins/main/response/response.d.ts +6 -1
  101. package/plugins/main/response/response.es6.js +22 -13
  102. package/plugins/main/response/response.js +21 -11
  103. package/plugins/main/return/index.d.ts +1 -0
  104. package/plugins/main/return/index.es6.js +1 -0
  105. package/plugins/main/return/index.js +9 -0
  106. package/plugins/main/return/return.d.ts +4 -0
  107. package/plugins/main/return/return.es6.js +10 -0
  108. package/plugins/main/return/return.js +14 -0
  109. package/plugins/main/server/server.d.ts +6 -5
  110. package/plugins/main/server/server.es6.js +43 -16
  111. package/plugins/main/server/server.js +42 -15
  112. package/plugins/main/tag/tag.d.ts +3 -2
  113. package/plugins/main/tag/tag.es6.js +6 -4
  114. package/plugins/main/tag/tag.js +5 -3
  115. package/plugins/main/variable/variable.d.ts +5 -5
  116. package/plugins/main/variable/variable.es6.js +3 -1
  117. package/plugins/main/variable/variable.js +3 -1
  118. package/plugins/request/cms/cms.d.ts +1 -0
  119. package/plugins/request/cms/cms.es6.js +3 -4
  120. package/plugins/request/cms/cms.js +2 -3
  121. package/plugins/request/cookie/cookie.es6.js +3 -19
  122. package/plugins/request/cookie/cookie.js +3 -23
  123. package/plugins/request/error/error.d.ts +41 -40
  124. package/plugins/request/error/error.es6.js +48 -45
  125. package/plugins/request/error/error.js +47 -44
  126. package/plugins/request/file/file.d.ts +1 -0
  127. package/plugins/request/file/file.es6.js +5 -6
  128. package/plugins/request/file/file.js +4 -5
  129. package/plugins/request/header/header.es6.js +1 -1
  130. package/plugins/request/header/header.js +1 -1
  131. package/plugins/request/proxy/proxy.d.ts +4 -1
  132. package/plugins/request/proxy/proxy.es6.js +5 -2
  133. package/plugins/request/proxy/proxy.js +5 -2
  134. package/plugins/request/redirect/redirect.d.ts +8 -7
  135. package/plugins/request/redirect/redirect.es6.js +7 -7
  136. package/plugins/request/redirect/redirect.js +7 -7
  137. package/plugins/request/success/success.d.ts +8 -6
  138. package/plugins/request/success/success.es6.js +21 -11
  139. package/plugins/request/success/success.js +20 -10
  140. package/plugins/schema/any/any.d.ts +5 -0
  141. package/plugins/schema/any/any.es6.js +27 -0
  142. package/plugins/schema/any/any.js +31 -0
  143. package/plugins/schema/array/array.d.ts +1 -0
  144. package/plugins/schema/array/array.es6.js +3 -3
  145. package/plugins/schema/array/array.js +2 -2
  146. package/plugins/schema/binary/binary.d.ts +3 -3
  147. package/plugins/schema/date/date.d.ts +1 -1
  148. package/plugins/schema/date/date.es6.js +3 -3
  149. package/plugins/schema/date/date.js +3 -3
  150. package/plugins/schema/field/field.d.ts +2 -0
  151. package/plugins/schema/field/field.es6.js +8 -8
  152. package/plugins/schema/field/field.js +6 -6
  153. package/plugins/schema/index.d.ts +1 -0
  154. package/plugins/schema/index.es6.js +1 -0
  155. package/plugins/schema/index.js +1 -0
  156. package/plugins/schema/integer/integer.d.ts +3 -3
  157. package/plugins/schema/integer/integer.es6.js +1 -1
  158. package/plugins/schema/integer/integer.js +1 -1
  159. package/plugins/schema/number/number.d.ts +2 -2
  160. package/plugins/schema/number/number.es6.js +1 -1
  161. package/plugins/schema/number/number.js +1 -1
  162. package/plugins/schema/object/object.d.ts +1 -0
  163. package/plugins/schema/object/object.es6.js +20 -7
  164. package/plugins/schema/object/object.js +19 -6
  165. package/plugins/schema/string/string.d.ts +2 -2
  166. package/plugins/schema/string/string.es6.js +44 -30
  167. package/plugins/schema/string/string.js +44 -30
  168. package/plugins/schema/tuple/tuple.d.ts +1 -0
  169. package/plugins/schema/tuple/tuple.es6.js +5 -5
  170. package/plugins/schema/tuple/tuple.js +4 -4
  171. package/plugins/schema/uuid/uuid.es6.js +1 -1
  172. package/plugins/schema/uuid/uuid.js +1 -1
  173. package/plugins/utils/blacklist/blacklist.d.ts +5 -0
  174. package/plugins/utils/blacklist/blacklist.es6.js +17 -0
  175. package/plugins/utils/blacklist/blacklist.js +21 -0
  176. package/plugins/utils/blacklist/index.d.ts +1 -0
  177. package/plugins/utils/blacklist/index.es6.js +1 -0
  178. package/plugins/utils/blacklist/index.js +9 -0
  179. package/plugins/utils/dts/dts.d.ts +2 -1
  180. package/plugins/utils/dts/dts.es6.js +2 -2
  181. package/plugins/utils/dts/dts.js +2 -2
  182. package/plugins/utils/env/env.d.ts +7 -0
  183. package/plugins/utils/env/env.es6.js +11 -0
  184. package/plugins/utils/{prod/prod.js → env/env.js} +5 -4
  185. package/plugins/utils/env/index.d.ts +1 -0
  186. package/plugins/utils/env/index.es6.js +1 -0
  187. package/plugins/utils/{dev → env}/index.js +2 -2
  188. package/plugins/utils/index.d.ts +4 -2
  189. package/plugins/utils/index.es6.js +4 -2
  190. package/plugins/utils/index.js +4 -2
  191. package/plugins/utils/protection/index.d.ts +1 -0
  192. package/plugins/utils/protection/index.es6.js +1 -0
  193. package/plugins/utils/protection/index.js +9 -0
  194. package/plugins/utils/protection/protection.d.ts +9 -0
  195. package/plugins/utils/protection/protection.es6.js +35 -0
  196. package/plugins/utils/protection/protection.js +39 -0
  197. package/plugins/utils/swagger/swagger.es6.js +10 -8
  198. package/plugins/utils/swagger/swagger.js +10 -8
  199. package/plugins/utils/whitelist/index.d.ts +1 -0
  200. package/plugins/utils/whitelist/index.es6.js +1 -0
  201. package/plugins/utils/whitelist/index.js +9 -0
  202. package/plugins/utils/whitelist/whitelist.d.ts +5 -0
  203. package/plugins/utils/whitelist/whitelist.es6.js +19 -0
  204. package/plugins/utils/whitelist/whitelist.js +23 -0
  205. package/types.d.ts +15 -23
  206. package/utils/FileData/Bin.d.ts +13 -13
  207. package/utils/FileData/Bin.es6.js +2 -2
  208. package/utils/FileData/Bin.js +2 -2
  209. package/utils/action/Action.d.ts +17 -14
  210. package/utils/action/Action.es6.js +102 -78
  211. package/utils/action/Action.js +102 -78
  212. package/utils/dateFormat/dateFormat.d.ts +1 -1
  213. package/utils/dateFormat/dateFormat.es6.js +1 -1
  214. package/utils/dateFormat/dateFormat.js +1 -1
  215. package/utils/decorators/once/once.es6.js +1 -1
  216. package/utils/decorators/once/once.js +1 -1
  217. package/utils/generateTypes/generateTypes.d.ts +2 -2
  218. package/utils/generateTypes/generateTypes.es6.js +85 -25
  219. package/utils/generateTypes/generateTypes.js +85 -25
  220. package/utils/getEndpoint/getEndpoint.es6.js +2 -2
  221. package/utils/getEndpoint/getEndpoint.js +2 -2
  222. package/utils/getOrAdd/getOrAdd.d.ts +1 -1
  223. package/utils/httpOnStart/httpOnStart.d.ts +1 -1
  224. package/utils/httpOnStart/httpOnStart.es6.js +1 -1
  225. package/utils/httpOnStart/httpOnStart.js +1 -1
  226. package/utils/rules/binaryAccept/binaryAccept.es6.js +2 -2
  227. package/utils/rules/binaryAccept/binaryAccept.js +2 -2
  228. package/utils/rules/dateTo/dateTo.d.ts +1 -1
  229. package/utils/rules/helpers.d.ts +1 -1
  230. package/utils/rules/index.d.ts +0 -1
  231. package/utils/rules/index.es6.js +0 -1
  232. package/utils/rules/index.js +0 -1
  233. package/utils/rules/int/int.es6.js +2 -2
  234. package/utils/rules/int/int.js +2 -2
  235. package/utils/rules/max/max.d.ts +1 -1
  236. package/utils/rules/max/max.es6.js +3 -3
  237. package/utils/rules/max/max.js +3 -3
  238. package/utils/rules/maxBin/maxBin.es6.js +2 -2
  239. package/utils/rules/maxBin/maxBin.js +2 -2
  240. package/utils/rules/maxDate/maxDate.es6.js +1 -1
  241. package/utils/rules/maxDate/maxDate.js +1 -1
  242. package/utils/rules/maxLength/maxLength.es6.js +2 -2
  243. package/utils/rules/maxLength/maxLength.js +2 -2
  244. package/utils/rules/min/min.d.ts +1 -1
  245. package/utils/rules/min/min.es6.js +3 -3
  246. package/utils/rules/min/min.js +3 -3
  247. package/utils/rules/minBin/minBin.es6.js +2 -2
  248. package/utils/rules/minBin/minBin.js +2 -2
  249. package/utils/rules/minDate/minDate.es6.js +1 -1
  250. package/utils/rules/minDate/minDate.js +1 -1
  251. package/utils/rules/minLength/minLength.es6.js +2 -2
  252. package/utils/rules/minLength/minLength.js +2 -2
  253. package/utils/rules/objectOf/objectOf.d.ts +1 -1
  254. package/utils/rules/objectOf/objectOf.es6.js +11 -1
  255. package/utils/rules/objectOf/objectOf.js +11 -1
  256. package/utils/rules/pattern/pattern.d.ts +1 -1
  257. package/utils/rules/pattern/pattern.es6.js +2 -1
  258. package/utils/rules/pattern/pattern.js +2 -1
  259. package/example/app/App/App.d.ts +0 -1
  260. package/example/app/App/index.d.ts +0 -1
  261. package/example/index.d.ts +0 -1
  262. package/example/requests/index.d.ts +0 -1
  263. package/example/requests/todo/AddTodo/AddTodo.d.ts +0 -1
  264. package/example/requests/todo/AddTodo/index.d.ts +0 -1
  265. package/example/requests/todo/DeleteTodo/DeleteTodo.d.ts +0 -1
  266. package/example/requests/todo/DeleteTodo/index.d.ts +0 -1
  267. package/example/requests/todo/EditTodo/EditTodo.d.ts +0 -1
  268. package/example/requests/todo/EditTodo/index.d.ts +0 -1
  269. package/example/requests/todo/GetTodo/GetTodo.d.ts +0 -1
  270. package/example/requests/todo/GetTodo/index.d.ts +0 -1
  271. package/example/requests/todo/GetTodos/GetTodos.d.ts +0 -1
  272. package/example/requests/todo/GetTodos/index.d.ts +0 -1
  273. package/example/requests/todo/index.d.ts +0 -5
  274. package/example/requests/todo/todos.d.ts +0 -1
  275. package/example/schemas/app/ListQueryParams/ListQueryParams.d.ts +0 -1
  276. package/example/schemas/app/ListQueryParams/index.d.ts +0 -1
  277. package/example/schemas/app/ListSchema/ListSchema.d.ts +0 -4
  278. package/example/schemas/app/ListSchema/index.d.ts +0 -1
  279. package/example/schemas/app/index.d.ts +0 -2
  280. package/example/schemas/index.d.ts +0 -2
  281. package/example/schemas/todo/TodoSchema/TodoSchema.d.ts +0 -4
  282. package/example/schemas/todo/TodoSchema/index.d.ts +0 -1
  283. package/example/schemas/todo/index.d.ts +0 -1
  284. package/example/tags/Todo/Todo.d.ts +0 -1
  285. package/example/tags/Todo/index.d.ts +0 -1
  286. package/example/tags/index.d.ts +0 -1
  287. package/hooks/useRequestPlugin/index.d.ts +0 -1
  288. package/hooks/useRequestPlugin/index.es6.js +0 -1
  289. package/hooks/useRequestPlugin/index.js +0 -9
  290. package/hooks/useRequestPlugin/useRequestPlugin.d.ts +0 -2
  291. package/hooks/useRequestPlugin/useRequestPlugin.es6.js +0 -13
  292. package/hooks/useRequestPlugin/useRequestPlugin.js +0 -17
  293. package/openApi.test.d.ts +0 -1
  294. package/plugins/main/fallback/fallback.d.ts +0 -4
  295. package/plugins/main/fallback/fallback.es6.js +0 -19
  296. package/plugins/main/fallback/fallback.js +0 -23
  297. package/plugins/main/fallback/index.d.ts +0 -1
  298. package/plugins/main/fallback/index.es6.js +0 -1
  299. package/plugins/main/fallback/index.js +0 -9
  300. package/plugins/main/request/index.d.ts +0 -1
  301. package/plugins/main/request/index.es6.js +0 -1
  302. package/plugins/main/request/index.js +0 -9
  303. package/plugins/main/request/request.d.ts +0 -4
  304. package/plugins/main/request/request.es6.js +0 -21
  305. package/plugins/main/request/request.js +0 -25
  306. package/plugins/utils/dev/dev.d.ts +0 -4
  307. package/plugins/utils/dev/dev.es6.js +0 -10
  308. package/plugins/utils/dev/index.d.ts +0 -1
  309. package/plugins/utils/dev/index.es6.js +0 -1
  310. package/plugins/utils/prod/index.d.ts +0 -1
  311. package/plugins/utils/prod/index.es6.js +0 -1
  312. package/plugins/utils/prod/prod.d.ts +0 -4
  313. package/plugins/utils/prod/prod.es6.js +0 -10
  314. package/utils/decorators/once/once.test.d.ts +0 -1
  315. package/utils/generateTypes/generateTypes.test.d.ts +0 -1
  316. package/utils/parseSearch/parseSearch.test.d.ts +0 -1
  317. package/utils/rules/any/any.d.ts +0 -1
  318. package/utils/rules/any/any.es6.js +0 -5
  319. package/utils/rules/any/any.js +0 -9
  320. /package/{utils/rules → plugins/schema}/any/index.d.ts +0 -0
  321. /package/{utils/rules → plugins/schema}/any/index.es6.js +0 -0
  322. /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,109 +582,399 @@ This section contains elements of utils.
316
582
  [← back](#index)
317
583
 
318
584
  [\<swagger>](#swagger)
319
- [\<dev>](#dev)
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
- Use `<swagger>` element to add Swagger UI documentation.
329
- `<swagger>` element MUST be placed in `<api>` element.
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
- <swagger />
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
- Open http://localhost:80/swagger-ui
343
- You will see Swagger UI documentation.
904
+ #### excludeIp
344
905
 
345
- You can change the Swagger UI URL path by `path` property of `<swagger>` element.
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
- <swagger path='/swagger' />
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
- ### \<dev>
928
+ #### cookieKey
359
929
 
360
- [← back](#utils)
930
+ This prop sets a cookie field name used to store protection of a user.
361
931
 
362
- Everything inside <dev> will work when `NODE_ENV` equals `development`.
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
- <dev>
370
- <swagger />
371
- </dev>
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
- ### \<dts>
378
-
379
- [← back](#utils)
953
+ #### searchKey
380
954
 
381
- Use `<dts>` element to add types generation.
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
- `<dts>` has a required prop of `path`. This is a path of api TypeScript types file, `<dts>` generates it.
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
- <dev>
392
- <dts path='src/api.d.ts' />
393
- </dev>
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
- ## 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
1024
1831
 
1025
- [← back](#index)
1832
+ A description of the `null`.
1026
1833
 
1027
- [\<null>](#null)
1028
- [\<boolean>](#boolean)
1029
- [\<string>](#string)
1030
- [\<number>](#number)
1031
- [\<integer>](#integer)
1032
- [\<date>](#date)
1033
- [\<uuid>](#uuid)
1034
- [\<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
+ ```
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
- <object
2378
- description='The object of a user'
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 `<object>`.
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
- ## Run-Time
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
- This element MUST be placed in `<endpoint>` element.
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='get' path='/partners'>
2510
- <request>
2511
- <success>
2512
- {{partners: []}}
2513
- </success>
2514
- </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>
2515
3273
  </endpoint>
2516
3274
  </api>
2517
3275
  </server>
2518
3276
  )
2519
3277
  ```
2520
3278
 
2521
- You can place a component inside it.
2522
- The component will run when the endpoint will be triggered.
3279
+ ## Run-Time
2523
3280
 
2524
- *src/app.tsx*
2525
- ```typescript jsx
2526
- import { GetPartners } from './GetPartners'
3281
+ Next elements relate to run-time action.
3282
+ This action calls on user request.
2527
3283
 
2528
- export default (
2529
- <server>
2530
- <api>
2531
- <endpoint method='get' path='/partners'>
2532
- <request>
2533
- <GetPartners />
2534
- </request>
2535
- </endpoint>
2536
- </api>
2537
- </server>
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
- *src/GetPartners.tsx*
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
- <api>
2561
- <fallback>
2562
- <success />
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
- <api>
2580
- <fallback>
2581
- <success>
2582
- {data}
2583
- </success>
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
- <api>
2603
- <fallback>
2604
- <success status='created'>
2605
- {data}
2606
- </success>
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
- <api>
2624
- <fallback>
2625
- <success status={201}>
2626
- {data}
2627
- </success>
2628
- </fallback>
2629
- </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>
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 [\<request>](#request) or [\<fallback>](#fallback).
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
- <api>
2646
- <fallback>
2647
- <error />
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
- <api>
2663
- <fallback>
2664
- <error>
2665
- {data}
2666
- </error>
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
- <api>
2685
- <fallback>
2686
- <error status='notFound'>
2687
- {data}
2688
- </error>
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
- <api>
2706
- <fallback>
2707
- <error status={404}>
2708
- {data}
2709
- </error>
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
- <api>
2740
- <fallback>
2741
- <error
2742
- code='noUser'
2743
- status='notFound'>
2744
- {data}
2745
- </error>
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 [\<request>](#request) or [\<fallback>](#fallback).
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
- <request>
3534
+ <return>
2788
3535
  <proxy to='https://...' />
2789
- </request>
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 [\<request>](#request) or [\<fallback>](#fallback).
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
- <request>
3562
+ <return>
2816
3563
  <redirect to='https://...' />
2817
- </request>
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
- <request>
3587
+ <return>
2841
3588
  <redirect
2842
3589
  status='found'
2843
3590
  to='https://...'
2844
3591
  />
2845
- </request>
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 [\<request>](#request) or [\<fallback>](#fallback).
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
- <api>
2871
- <fallback>
2872
- <cms />
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 looks at project folder.
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
- <api>
2892
- <fallback>
2893
- <cms dir='src' />
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
- <fallback>
3656
+ <return>
2913
3657
  <cms />
2914
- </fallback>
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
- <fallback>
3674
+ <return>
2931
3675
  <cms prefix='/api' />
2932
- </fallback>
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
- <api prefix='/src'>
2949
- <fallback>
2950
- <cms>
2951
- <error status={404} />
2952
- </cms>
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 [\<request>](#request) or [\<fallback>](#fallback).
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
- <api>
2974
- <fallback>
2975
- <file
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
- <api prefix='/src'>
2995
- <fallback>
2996
- <file path='file_is_not_exist.txt'>
2997
- <error status={404} />
2998
- </file>
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 [\<request>](#request) or [\<fallback>](#fallback).
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
- <api prefix='/src'>
3018
- <fallback>
3019
- <header
3020
- key='Cache-Control'
3021
- value='no-cache, no-store, must-revalidate'
3022
- />
3023
- <success />
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 [\<request>](#request) or [\<fallback>](#fallback).
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
- <api prefix='/src'>
3043
- <fallback>
3044
- <cookie
3045
- key='token'
3046
- value='...'
3047
- />
3048
- <cookie
3049
- key='removedCookie'
3050
- />
3051
- <success />
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
- <api prefix='/src'>
3068
- <fallback>
3069
- <cookie
3070
- domain='.example.com'
3071
- key='token'
3072
- value='...'
3073
- />
3074
- <success />
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
- <api prefix='/src'>
3096
- <fallback>
3097
- <cookie
3098
- expires={new Date('2050-01-01')}
3099
- key='token'
3100
- value='...'
3101
- />
3102
- <success />
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
- <api prefix='/src'>
3119
- <fallback>
3120
- <cookie
3121
- httpOnly
3122
- key='token'
3123
- value='...'
3124
- />
3125
- <success />
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
- <api prefix='/src'>
3142
- <fallback>
3143
- <cookie
3144
- httpOnly
3145
- maxAge={9999}
3146
- key='token'
3147
- value='...'
3148
- />
3149
- <success />
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
- <api prefix='/src'>
3166
- <fallback>
3167
- <cookie
3168
- httpOnly
3169
- maxAge={9999}
3170
- path='/src'
3171
- key='token'
3172
- value='...'
3173
- />
3174
- <success />
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
- <api prefix='/src'>
3196
- <fallback>
3197
- <cookie
3198
- httpOnly
3199
- priority='high'
3200
- path='/src'
3201
- key='token'
3202
- value='...'
3203
- />
3204
- <success />
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
- <api prefix='/src'>
3229
- <fallback>
3230
- <cookie
3231
- httpOnly
3232
- sameSite
3233
- priority='high'
3234
- path='/src'
3235
- key='token'
3236
- value='...'
3237
- />
3238
- <success />
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
- <api prefix='/src'>
3258
- <fallback>
3259
- <cookie
3260
- httpOnly
3261
- secure
3262
- key='token'
3263
- value='...'
3264
- />
3265
- <success />
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
- <api prefix='/src'>
3301
- <fallback>
3302
- <SetToken
3303
- value='...'
3304
- />
3305
- <success />
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
- [useRequestPlugin](#userequestplugin)
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 [\<request>](#request) or [\<fallback>](#fallback).
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 [\<request>](#request) or [\<fallback>](#fallback).
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 [\<request>](#request) or [\<fallback>](#fallback).
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 [\<request>](#request) or [\<fallback>](#fallback).
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 [\<request>](#request) or [\<fallback>](#fallback).
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 [\<request>](#request) or [\<fallback>](#fallback).
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 [\<request>](#request) or [\<fallback>](#fallback).
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 [\<request>](#request) or [\<fallback>](#fallback).
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 [\<request>](#request) or [\<fallback>](#fallback).
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
- ### useRequestPlugin
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 [\<api>](#api).
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
- useRequestPlugin((req, res) => {
3527
- if (req.url.startsWith('/secret-endpoint')) {
3528
- res.statusCode = 200
3529
- res.write('A secret message')
3530
- res.end()
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
- <api>
3546
- <fallback>
3547
- <error />
3548
- </fallback>
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)