@innet/server 2.0.0-alpha.26 → 2.0.0-alpha.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/index.es6.js +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useIsServerHttps/index.d.ts +1 -0
- package/hooks/useIsServerHttps/index.es6.js +1 -0
- package/hooks/useIsServerHttps/index.js +10 -0
- package/hooks/useIsServerHttps/useIsServerHttps.d.ts +3 -0
- package/hooks/useIsServerHttps/useIsServerHttps.es6.js +14 -0
- package/hooks/useIsServerHttps/useIsServerHttps.js +19 -0
- package/index.es6.js +1 -0
- package/index.js +3 -0
- package/package.json +1 -1
- package/plugins/main/server/server.es6.js +2 -0
- package/plugins/main/server/server.js +2 -0
- package/plugins/request/success/success.es6.js +2 -0
- package/plugins/request/success/success.js +2 -0
- package/utils/generateTypes/generateTypes.es6.js +1 -1
- package/utils/generateTypes/generateTypes.js +1 -1
package/README.md
CHANGED
|
@@ -1710,6 +1710,8 @@ return (
|
|
|
1710
1710
|
[\<uuid>](#uuid)
|
|
1711
1711
|
[\<binary>](#binary)
|
|
1712
1712
|
|
|
1713
|
+
---
|
|
1714
|
+
|
|
1713
1715
|
### \<any>
|
|
1714
1716
|
|
|
1715
1717
|
[← back](#primitive-data)
|
|
@@ -4022,6 +4024,8 @@ Server start
|
|
|
4022
4024
|
|
|
4023
4025
|
Both
|
|
4024
4026
|
[useServer](#useserver)
|
|
4027
|
+
[usePort](#useport)
|
|
4028
|
+
[useIsServerHttps](#useisserverhttps)
|
|
4025
4029
|
[useComponentName](#usecomponentname)
|
|
4026
4030
|
|
|
4027
4031
|
---
|
|
@@ -4261,6 +4265,53 @@ export function Component () {
|
|
|
4261
4265
|
}
|
|
4262
4266
|
```
|
|
4263
4267
|
|
|
4268
|
+
### usePort
|
|
4269
|
+
|
|
4270
|
+
[← back](#hooks)
|
|
4271
|
+
|
|
4272
|
+
This hook MUST be used in a component placed in [\<server>](#server).
|
|
4273
|
+
This hook returns current http(s) server port.
|
|
4274
|
+
|
|
4275
|
+
*src/LocalHost.tsx*
|
|
4276
|
+
```typescript jsx
|
|
4277
|
+
import { usePort } from '@innet/sever'
|
|
4278
|
+
|
|
4279
|
+
export function LocalHost () {
|
|
4280
|
+
const port = usePort()
|
|
4281
|
+
|
|
4282
|
+
return (
|
|
4283
|
+
<host
|
|
4284
|
+
description='Development'
|
|
4285
|
+
url={`http://localhost:${port}/api`}
|
|
4286
|
+
/>
|
|
4287
|
+
)
|
|
4288
|
+
}
|
|
4289
|
+
```
|
|
4290
|
+
|
|
4291
|
+
### useIsServerHttps
|
|
4292
|
+
|
|
4293
|
+
[← back](#hooks)
|
|
4294
|
+
|
|
4295
|
+
This hook MUST be used in a component placed in [\<server>](#server).
|
|
4296
|
+
This hook returns `true` if it is https server and `false` if not.
|
|
4297
|
+
|
|
4298
|
+
*src/LocalHost.tsx*
|
|
4299
|
+
```typescript jsx
|
|
4300
|
+
import { usePort, useIsServerHttps } from '@innet/sever'
|
|
4301
|
+
|
|
4302
|
+
export function LocalHost () {
|
|
4303
|
+
const https = useIsServerHttps() ? 'https' : 'http'
|
|
4304
|
+
const port = usePort()
|
|
4305
|
+
|
|
4306
|
+
return (
|
|
4307
|
+
<host
|
|
4308
|
+
description='Development'
|
|
4309
|
+
url={`${https}://localhost:${port}/api`}
|
|
4310
|
+
/>
|
|
4311
|
+
)
|
|
4312
|
+
}
|
|
4313
|
+
```
|
|
4314
|
+
|
|
4264
4315
|
### useComponentName
|
|
4265
4316
|
|
|
4266
4317
|
[← back](#hooks)
|
package/hooks/index.d.ts
CHANGED
package/hooks/index.es6.js
CHANGED
package/hooks/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useIsServerHttps';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { serverHttpsContext, useIsServerHttps } from './useIsServerHttps.es6.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var useIsServerHttps = require('./useIsServerHttps.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.serverHttpsContext = useIsServerHttps.serverHttpsContext;
|
|
10
|
+
exports.useIsServerHttps = useIsServerHttps.useIsServerHttps;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Context, useContext } from '@innet/jsx';
|
|
2
|
+
import '../useThrow/index.es6.js';
|
|
3
|
+
import { useThrow } from '../useThrow/useThrow.es6.js';
|
|
4
|
+
|
|
5
|
+
const serverHttpsContext = new Context();
|
|
6
|
+
function useIsServerHttps() {
|
|
7
|
+
const https = useContext(serverHttpsContext);
|
|
8
|
+
if (https === undefined) {
|
|
9
|
+
useThrow('{type} MUST BE in <server>');
|
|
10
|
+
}
|
|
11
|
+
return https;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { serverHttpsContext, useIsServerHttps };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsx = require('@innet/jsx');
|
|
6
|
+
require('../useThrow/index.js');
|
|
7
|
+
var useThrow = require('../useThrow/useThrow.js');
|
|
8
|
+
|
|
9
|
+
const serverHttpsContext = new jsx.Context();
|
|
10
|
+
function useIsServerHttps() {
|
|
11
|
+
const https = jsx.useContext(serverHttpsContext);
|
|
12
|
+
if (https === undefined) {
|
|
13
|
+
useThrow.useThrow('{type} MUST BE in <server>');
|
|
14
|
+
}
|
|
15
|
+
return https;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.serverHttpsContext = serverHttpsContext;
|
|
19
|
+
exports.useIsServerHttps = useIsServerHttps;
|
package/index.es6.js
CHANGED
|
@@ -114,3 +114,4 @@ export { useClientIp } from './hooks/useClientIp/useClientIp.es6.js';
|
|
|
114
114
|
export { serverPlugins, useServerPlugins } from './hooks/useServerPlugins/useServerPlugins.es6.js';
|
|
115
115
|
export { objectSchemaContext, useObjectSchemaContext } from './hooks/useObjectSchemaContext/useObjectSchemaContext.es6.js';
|
|
116
116
|
export { serverPortContext, useServerPort } from './hooks/useServerPort/useServerPort.es6.js';
|
|
117
|
+
export { serverHttpsContext, useIsServerHttps } from './hooks/useIsServerHttps/useIsServerHttps.es6.js';
|
package/index.js
CHANGED
|
@@ -118,6 +118,7 @@ var useClientIp = require('./hooks/useClientIp/useClientIp.js');
|
|
|
118
118
|
var useServerPlugins = require('./hooks/useServerPlugins/useServerPlugins.js');
|
|
119
119
|
var useObjectSchemaContext = require('./hooks/useObjectSchemaContext/useObjectSchemaContext.js');
|
|
120
120
|
var useServerPort = require('./hooks/useServerPort/useServerPort.js');
|
|
121
|
+
var useIsServerHttps = require('./hooks/useIsServerHttps/useIsServerHttps.js');
|
|
121
122
|
|
|
122
123
|
|
|
123
124
|
|
|
@@ -262,3 +263,5 @@ exports.objectSchemaContext = useObjectSchemaContext.objectSchemaContext;
|
|
|
262
263
|
exports.useObjectSchemaContext = useObjectSchemaContext.useObjectSchemaContext;
|
|
263
264
|
exports.serverPortContext = useServerPort.serverPortContext;
|
|
264
265
|
exports.useServerPort = useServerPort.useServerPort;
|
|
266
|
+
exports.serverHttpsContext = useIsServerHttps.serverHttpsContext;
|
|
267
|
+
exports.useIsServerHttps = useIsServerHttps.useIsServerHttps;
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ import '../../../utils/index.es6.js';
|
|
|
9
9
|
import { serverContext } from '../../../hooks/useServer/useServer.es6.js';
|
|
10
10
|
import { serverPlugins } from '../../../hooks/useServerPlugins/useServerPlugins.es6.js';
|
|
11
11
|
import { serverPortContext } from '../../../hooks/useServerPort/useServerPort.es6.js';
|
|
12
|
+
import { serverHttpsContext } from '../../../hooks/useIsServerHttps/useIsServerHttps.es6.js';
|
|
12
13
|
import { Action } from '../../../utils/action/Action.es6.js';
|
|
13
14
|
import { actionContext } from '../../../hooks/useAction/useAction.es6.js';
|
|
14
15
|
|
|
@@ -39,6 +40,7 @@ const server = () => {
|
|
|
39
40
|
serverContext.set(handler, { port, server });
|
|
40
41
|
serverPlugins.set(handler, plugins);
|
|
41
42
|
serverPortContext.set(handler, port);
|
|
43
|
+
serverHttpsContext.set(handler, https);
|
|
42
44
|
onDestroy(() => {
|
|
43
45
|
server.close();
|
|
44
46
|
});
|
|
@@ -13,6 +13,7 @@ require('../../../utils/index.js');
|
|
|
13
13
|
var useServer = require('../../../hooks/useServer/useServer.js');
|
|
14
14
|
var useServerPlugins = require('../../../hooks/useServerPlugins/useServerPlugins.js');
|
|
15
15
|
var useServerPort = require('../../../hooks/useServerPort/useServerPort.js');
|
|
16
|
+
var useIsServerHttps = require('../../../hooks/useIsServerHttps/useIsServerHttps.js');
|
|
16
17
|
var Action = require('../../../utils/action/Action.js');
|
|
17
18
|
var useAction = require('../../../hooks/useAction/useAction.js');
|
|
18
19
|
|
|
@@ -50,6 +51,7 @@ const server = () => {
|
|
|
50
51
|
useServer.serverContext.set(handler, { port, server });
|
|
51
52
|
useServerPlugins.serverPlugins.set(handler, plugins);
|
|
52
53
|
useServerPort.serverPortContext.set(handler, port);
|
|
54
|
+
useIsServerHttps.serverHttpsContext.set(handler, https);
|
|
53
55
|
watchState.onDestroy(() => {
|
|
54
56
|
server.close();
|
|
55
57
|
});
|
|
@@ -28,7 +28,9 @@ const success = () => {
|
|
|
28
28
|
const contentType = type || (['bigint', 'boolean', 'number', 'string'].includes(typeof child)
|
|
29
29
|
? 'text/plain'
|
|
30
30
|
: 'application/json');
|
|
31
|
+
const content = contentType === 'application/json' ? JSONString(child) : String(child);
|
|
31
32
|
res.setHeader('Content-Type', contentType);
|
|
33
|
+
res.setHeader('Content-Length', content.length);
|
|
32
34
|
if (contentType === 'application/json') {
|
|
33
35
|
res.write(JSONString(child));
|
|
34
36
|
}
|
|
@@ -32,7 +32,9 @@ const success = () => {
|
|
|
32
32
|
const contentType = type || (['bigint', 'boolean', 'number', 'string'].includes(typeof child)
|
|
33
33
|
? 'text/plain'
|
|
34
34
|
: 'application/json');
|
|
35
|
+
const content = contentType === 'application/json' ? JSONString.JSONString(child) : String(child);
|
|
35
36
|
res.setHeader('Content-Type', contentType);
|
|
37
|
+
res.setHeader('Content-Length', content.length);
|
|
36
38
|
if (contentType === 'application/json') {
|
|
37
39
|
res.write(JSONString.JSONString(child));
|
|
38
40
|
}
|
|
@@ -106,7 +106,7 @@ function generateTypes(docs, namespace = 'Api') {
|
|
|
106
106
|
query: '',
|
|
107
107
|
};
|
|
108
108
|
for (const param of parameters) {
|
|
109
|
-
const splitter = param.in === 'path' || hasDefault(param.schema) ? ':' : '?:';
|
|
109
|
+
const splitter = param.in === 'path' || hasDefault(param.schema) || param.required ? ':' : '?:';
|
|
110
110
|
params[param.in] += ` ${param.name}${splitter} ${generateSchemaTypes(param.schema)}`;
|
|
111
111
|
}
|
|
112
112
|
if (params.path) {
|
|
@@ -110,7 +110,7 @@ function generateTypes(docs, namespace = 'Api') {
|
|
|
110
110
|
query: '',
|
|
111
111
|
};
|
|
112
112
|
for (const param of parameters) {
|
|
113
|
-
const splitter = param.in === 'path' || hasDefault(param.schema) ? ':' : '?:';
|
|
113
|
+
const splitter = param.in === 'path' || hasDefault(param.schema) || param.required ? ':' : '?:';
|
|
114
114
|
params[param.in] += ` ${param.name}${splitter} ${generateSchemaTypes(param.schema)}`;
|
|
115
115
|
}
|
|
116
116
|
if (params.path) {
|