@logux/server 0.12.3 → 0.12.5
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 +4 -6
- package/add-sync-map/index.d.ts +30 -29
- package/add-sync-map/index.js +4 -4
- package/base-server/hello.html +1 -1
- package/base-server/index.d.ts +397 -396
- package/base-server/index.js +308 -308
- package/bind-backend-proxy/index.js +77 -77
- package/bind-control-server/index.js +1 -1
- package/context/index.d.ts +34 -33
- package/context/index.js +1 -1
- package/create-http-server/index.js +4 -4
- package/create-reporter/index.js +107 -107
- package/human-formatter/index.js +13 -13
- package/index.d.ts +24 -24
- package/index.js +16 -16
- package/options-loader/index.js +2 -2
- package/options-loader/index.test.js +25 -25
- package/package.json +11 -11
- package/request/test.test.js +19 -19
- package/server/index.d.ts +27 -25
- package/server/index.js +56 -56
- package/server-client/index.d.ts +40 -39
- package/server-client/index.js +61 -61
- package/test-client/index.d.ts +47 -46
- package/test-client/index.js +28 -28
- package/test-server/index.d.ts +43 -42
- package/test-server/index.js +20 -20
- package/vite.config.ts +5 -5
package/human-formatter/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import yyyymmdd from 'yyyy-mm-dd'
|
|
3
|
-
import pico from 'picocolors'
|
|
1
|
+
import { once } from 'events'
|
|
4
2
|
import os from 'os'
|
|
3
|
+
import pico from 'picocolors'
|
|
4
|
+
import pino from 'pino'
|
|
5
5
|
import abstractTransport from 'pino-abstract-transport'
|
|
6
6
|
import { Transform } from 'stream'
|
|
7
|
-
import
|
|
8
|
-
import
|
|
7
|
+
import stripAnsi from 'strip-ansi'
|
|
8
|
+
import yyyymmdd from 'yyyy-mm-dd'
|
|
9
9
|
|
|
10
10
|
import { mulberry32, onceXmur3 } from './utils.js'
|
|
11
11
|
|
|
@@ -15,19 +15,19 @@ const SEPARATOR = os.EOL + os.EOL
|
|
|
15
15
|
const NEXT_LINE = os.EOL === '\n' ? '\r\v' : os.EOL
|
|
16
16
|
|
|
17
17
|
const PARAMS_BLACKLIST = {
|
|
18
|
-
|
|
19
|
-
msg: true,
|
|
18
|
+
component: true,
|
|
20
19
|
err: true,
|
|
21
|
-
pid: true,
|
|
22
20
|
hint: true,
|
|
23
|
-
|
|
24
|
-
name: true,
|
|
25
|
-
time: true,
|
|
21
|
+
hostname: true,
|
|
26
22
|
level: true,
|
|
27
23
|
listen: true,
|
|
24
|
+
msg: true,
|
|
25
|
+
name: true,
|
|
26
|
+
note: true,
|
|
27
|
+
pid: true,
|
|
28
28
|
server: true,
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
time: true,
|
|
30
|
+
v: true
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const LABELS = {
|
package/index.d.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
export { Action } from '@logux/core'
|
|
2
|
-
|
|
3
1
|
export {
|
|
2
|
+
addSyncMap,
|
|
3
|
+
addSyncMapFilter,
|
|
4
|
+
ChangedAt,
|
|
5
|
+
NoConflictResolution,
|
|
6
|
+
SyncMapData,
|
|
7
|
+
WithoutTime,
|
|
8
|
+
WithTime
|
|
9
|
+
} from './add-sync-map/index.js'
|
|
10
|
+
export { ALLOWED_META } from './allowed-meta/index.js'
|
|
11
|
+
export {
|
|
12
|
+
BaseServer,
|
|
4
13
|
BaseServerOptions,
|
|
14
|
+
Logger,
|
|
5
15
|
SendBackActions,
|
|
6
|
-
BaseServer,
|
|
7
16
|
ServerMeta,
|
|
8
|
-
wasNot403
|
|
9
|
-
Logger
|
|
17
|
+
wasNot403
|
|
10
18
|
} from './base-server/index.js'
|
|
19
|
+
export { ChannelContext, Context } from './context/index.js'
|
|
20
|
+
export { filterMeta } from './filter-meta/index.js'
|
|
11
21
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
del,
|
|
23
|
+
get,
|
|
14
24
|
patch,
|
|
15
25
|
post,
|
|
16
|
-
get,
|
|
17
26
|
put,
|
|
18
|
-
|
|
27
|
+
request,
|
|
28
|
+
ResponseError
|
|
19
29
|
} from './request/index.js'
|
|
20
|
-
export {
|
|
21
|
-
NoConflictResolution,
|
|
22
|
-
addSyncMapFilter,
|
|
23
|
-
WithoutTime,
|
|
24
|
-
SyncMapData,
|
|
25
|
-
addSyncMap,
|
|
26
|
-
ChangedAt,
|
|
27
|
-
WithTime
|
|
28
|
-
} from './add-sync-map/index.js'
|
|
29
|
-
export { TestServer, TestServerOptions } from './test-server/index.js'
|
|
30
|
-
export { TestClient, LoguxActionError } from './test-client/index.js'
|
|
31
|
-
export { Context, ChannelContext } from './context/index.js'
|
|
32
|
-
export { Server, ServerOptions } from './server/index.js'
|
|
33
30
|
export { ServerClient } from './server-client/index.js'
|
|
34
|
-
export {
|
|
35
|
-
export {
|
|
31
|
+
export { Server, ServerOptions } from './server/index.js'
|
|
32
|
+
export { LoguxActionError, TestClient } from './test-client/index.js'
|
|
33
|
+
export { TestServer, TestServerOptions } from './test-server/index.js'
|
|
34
|
+
|
|
35
|
+
export { Action } from '@logux/core'
|
package/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
export {
|
|
2
|
-
ResponseError,
|
|
3
|
-
request,
|
|
4
|
-
patch,
|
|
5
|
-
post,
|
|
6
|
-
get,
|
|
7
|
-
put,
|
|
8
|
-
del
|
|
9
|
-
} from './request/index.js'
|
|
10
|
-
export {
|
|
11
|
-
NoConflictResolution,
|
|
12
|
-
addSyncMapFilter,
|
|
13
2
|
addSyncMap,
|
|
14
|
-
|
|
3
|
+
addSyncMapFilter,
|
|
4
|
+
ChangedAt,
|
|
5
|
+
NoConflictResolution
|
|
15
6
|
} from './add-sync-map/index.js'
|
|
16
|
-
export { BaseServer, wasNot403 } from './base-server/index.js'
|
|
17
7
|
export { ALLOWED_META } from './allowed-meta/index.js'
|
|
18
|
-
export {
|
|
19
|
-
export { TestClient } from './test-client/index.js'
|
|
20
|
-
export { filterMeta } from './filter-meta/index.js'
|
|
8
|
+
export { BaseServer, wasNot403 } from './base-server/index.js'
|
|
21
9
|
export { Context } from './context/index.js'
|
|
10
|
+
export { filterMeta } from './filter-meta/index.js'
|
|
11
|
+
export {
|
|
12
|
+
del,
|
|
13
|
+
get,
|
|
14
|
+
patch,
|
|
15
|
+
post,
|
|
16
|
+
put,
|
|
17
|
+
request,
|
|
18
|
+
ResponseError
|
|
19
|
+
} from './request/index.js'
|
|
22
20
|
export { Server } from './server/index.js'
|
|
21
|
+
export { TestClient } from './test-client/index.js'
|
|
22
|
+
export { TestServer } from './test-server/index.js'
|
package/options-loader/index.js
CHANGED
|
@@ -99,9 +99,9 @@ function mapArgs(parsedCliArgs, argsSpec) {
|
|
|
99
99
|
function composeHelp(spec, argv) {
|
|
100
100
|
let options = Object.entries(spec.options).map(([name, option]) => ({
|
|
101
101
|
alias: option.alias ? composeCliAliasName(option.alias) : '',
|
|
102
|
-
|
|
102
|
+
description: option.description,
|
|
103
103
|
env: spec.envPrefix ? composeEnvName(spec.envPrefix, name) : '',
|
|
104
|
-
|
|
104
|
+
full: composeCliFullName(name)
|
|
105
105
|
}))
|
|
106
106
|
let nameColumnLength = Math.max(...options.map(it => it.full.length))
|
|
107
107
|
let envColumnLength = Math.max(...options.map(it => it.env.length))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { it, expect, describe } from 'vitest'
|
|
2
1
|
import { resolve } from 'path'
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { loadOptions,
|
|
4
|
+
import { loadOptions, number, oneOf } from './index.js'
|
|
5
5
|
|
|
6
6
|
function fakeProcess(argv, env = {}) {
|
|
7
7
|
return { argv, env }
|
|
@@ -11,13 +11,13 @@ describe('loadOptions', () => {
|
|
|
11
11
|
it('returns help', () => {
|
|
12
12
|
let [help, options] = loadOptions(
|
|
13
13
|
{
|
|
14
|
+
examples: ['$0'],
|
|
14
15
|
options: {
|
|
15
16
|
port: {
|
|
16
17
|
description: 'port',
|
|
17
18
|
parse: number
|
|
18
19
|
}
|
|
19
|
-
}
|
|
20
|
-
examples: ['$0']
|
|
20
|
+
}
|
|
21
21
|
},
|
|
22
22
|
fakeProcess(['node', 'test/test.js', '--help'])
|
|
23
23
|
)
|
|
@@ -44,13 +44,13 @@ describe('loadOptions', () => {
|
|
|
44
44
|
it('uses env for options', () => {
|
|
45
45
|
let [, options] = loadOptions(
|
|
46
46
|
{
|
|
47
|
+
envPrefix: 'LOGUX',
|
|
47
48
|
options: {
|
|
48
49
|
port: {
|
|
49
50
|
description: 'port',
|
|
50
51
|
parse: number
|
|
51
52
|
}
|
|
52
|
-
}
|
|
53
|
-
envPrefix: 'LOGUX'
|
|
53
|
+
}
|
|
54
54
|
},
|
|
55
55
|
fakeProcess([], {
|
|
56
56
|
LOGUX_PORT: '31337'
|
|
@@ -64,13 +64,13 @@ describe('loadOptions', () => {
|
|
|
64
64
|
it('uses dotenv file for options', () => {
|
|
65
65
|
let [, options] = loadOptions(
|
|
66
66
|
{
|
|
67
|
+
envPrefix: 'LOGUX',
|
|
67
68
|
options: {
|
|
68
69
|
port: {
|
|
69
70
|
description: 'port',
|
|
70
71
|
parse: number
|
|
71
72
|
}
|
|
72
|
-
}
|
|
73
|
-
envPrefix: 'LOGUX'
|
|
73
|
+
}
|
|
74
74
|
},
|
|
75
75
|
fakeProcess([], {}),
|
|
76
76
|
{
|
|
@@ -84,13 +84,13 @@ describe('loadOptions', () => {
|
|
|
84
84
|
it('composes correct env and CLI names for argument with complex name', () => {
|
|
85
85
|
let [, options] = loadOptions(
|
|
86
86
|
{
|
|
87
|
+
envPrefix: 'LOGUX',
|
|
87
88
|
options: {
|
|
88
89
|
somePort: {
|
|
89
90
|
description: 'port',
|
|
90
91
|
parse: number
|
|
91
92
|
}
|
|
92
|
-
}
|
|
93
|
-
envPrefix: 'LOGUX'
|
|
93
|
+
}
|
|
94
94
|
},
|
|
95
95
|
fakeProcess(['--some-port', '1'], {
|
|
96
96
|
LOGUX_SOME_PORT: '1'
|
|
@@ -104,15 +104,15 @@ describe('loadOptions', () => {
|
|
|
104
104
|
it('uses combined options', () => {
|
|
105
105
|
let [, options] = loadOptions(
|
|
106
106
|
{
|
|
107
|
+
envPrefix: 'LOGUX',
|
|
107
108
|
options: {
|
|
108
|
-
key: {
|
|
109
|
-
description: 'port'
|
|
110
|
-
},
|
|
111
109
|
cert: {
|
|
112
110
|
description: 'cert'
|
|
111
|
+
},
|
|
112
|
+
key: {
|
|
113
|
+
description: 'port'
|
|
113
114
|
}
|
|
114
|
-
}
|
|
115
|
-
envPrefix: 'LOGUX'
|
|
115
|
+
}
|
|
116
116
|
},
|
|
117
117
|
fakeProcess(['', '--key', './key.pem'], { LOGUX_CERT: './cert.pem' })
|
|
118
118
|
)
|
|
@@ -123,19 +123,19 @@ describe('loadOptions', () => {
|
|
|
123
123
|
|
|
124
124
|
it('uses arg and env in given priority', () => {
|
|
125
125
|
let optionsSpec = {
|
|
126
|
+
envPrefix: 'LOGUX',
|
|
126
127
|
options: {
|
|
127
|
-
|
|
128
|
-
description: '
|
|
129
|
-
parse: number
|
|
128
|
+
cert: {
|
|
129
|
+
description: 'cert'
|
|
130
130
|
},
|
|
131
131
|
key: {
|
|
132
132
|
description: 'key'
|
|
133
133
|
},
|
|
134
|
-
|
|
135
|
-
description: '
|
|
134
|
+
port: {
|
|
135
|
+
description: 'port',
|
|
136
|
+
parse: number
|
|
136
137
|
}
|
|
137
|
-
}
|
|
138
|
-
envPrefix: 'LOGUX'
|
|
138
|
+
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
let [, options1] = loadOptions(
|
|
@@ -172,12 +172,12 @@ describe('loadOptions', () => {
|
|
|
172
172
|
let [, options] = loadOptions(
|
|
173
173
|
{
|
|
174
174
|
options: {
|
|
175
|
+
key: {
|
|
176
|
+
description: 'key'
|
|
177
|
+
},
|
|
175
178
|
port: {
|
|
176
179
|
alias: 'p',
|
|
177
180
|
description: 'port'
|
|
178
|
-
},
|
|
179
|
-
key: {
|
|
180
|
-
description: 'key'
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logux/server",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.5",
|
|
4
4
|
"description": "Build own Logux server or make proxy between WebSocket and HTTP backend on any language",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logux",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
],
|
|
16
16
|
"author": "Andrey Sitnik <andrey@sitnik.ru>",
|
|
17
17
|
"license": "MIT",
|
|
18
|
-
"homepage": "https://logux.
|
|
18
|
+
"homepage": "https://logux.org/",
|
|
19
19
|
"repository": "logux/server",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": "^14.0.0 || ^16.0.0 || >=18.0.0"
|
|
@@ -27,22 +27,22 @@
|
|
|
27
27
|
"./package.json": "./package.json"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@logux/actions": "^0.3.
|
|
31
|
-
"@logux/core": "^0.8.
|
|
30
|
+
"@logux/actions": "^0.3.1",
|
|
31
|
+
"@logux/core": "^0.8.4",
|
|
32
32
|
"JSONStream": "^1.3.5",
|
|
33
33
|
"cookie": "^0.5.0",
|
|
34
|
-
"dotenv": "^16.
|
|
35
|
-
"fast-glob": "^3.
|
|
34
|
+
"dotenv": "^16.3.1",
|
|
35
|
+
"fast-glob": "^3.3.1",
|
|
36
36
|
"ip": "^1.1.8",
|
|
37
37
|
"nanodelay": "^2.0.2",
|
|
38
|
-
"nanoevents": "^
|
|
38
|
+
"nanoevents": "^8.0.0",
|
|
39
39
|
"nanoid": "^4.0.2",
|
|
40
|
-
"node-fetch": "^3.3.
|
|
40
|
+
"node-fetch": "^3.3.2",
|
|
41
41
|
"picocolors": "^1.0.0",
|
|
42
|
-
"pino": "8.
|
|
42
|
+
"pino": "8.15.0",
|
|
43
43
|
"pino-abstract-transport": "^1.0.0",
|
|
44
|
-
"semver": "^7.5.
|
|
45
|
-
"strip-ansi": "^7.0
|
|
44
|
+
"semver": "^7.5.4",
|
|
45
|
+
"strip-ansi": "^7.1.0",
|
|
46
46
|
"url-pattern": "^1.0.3",
|
|
47
47
|
"ws": "^8.13.0",
|
|
48
48
|
"yyyy-mm-dd": "^1.0.2"
|
package/request/test.test.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { it, expect } from 'vitest'
|
|
2
1
|
import { spy } from 'nanospy'
|
|
2
|
+
import { expect, it } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { del, get, patch, post, put, request, ResponseError } from '../index.js'
|
|
5
5
|
|
|
6
6
|
it('has error', () => {
|
|
7
7
|
let error = new ResponseError(
|
|
8
8
|
403,
|
|
9
9
|
'/a',
|
|
10
|
-
{
|
|
10
|
+
{ body: 'body', method: 'GET' },
|
|
11
11
|
'answer'
|
|
12
12
|
)
|
|
13
13
|
expect(error.name).toEqual('ResponseError')
|
|
@@ -25,19 +25,19 @@ it('throws an error on non-2xx response', async () => {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
await expect(
|
|
28
|
-
request('/a', {
|
|
28
|
+
request('/a', { body: 'body', method: 'GET' }, fetch)
|
|
29
29
|
).rejects.toThrow(
|
|
30
|
-
new ResponseError(403, '/a', {
|
|
30
|
+
new ResponseError(403, '/a', { body: 'body', method: 'GET' }, 'answer')
|
|
31
31
|
)
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
it('parses JSON body', async () => {
|
|
35
35
|
async function fetch() {
|
|
36
36
|
return {
|
|
37
|
-
status: 200,
|
|
38
37
|
async json() {
|
|
39
38
|
return { answer: '1' }
|
|
40
|
-
}
|
|
39
|
+
},
|
|
40
|
+
status: 200
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
expect(await request('/a', { method: 'GET' }, fetch)).toEqual({ answer: '1' })
|
|
@@ -45,10 +45,10 @@ it('parses JSON body', async () => {
|
|
|
45
45
|
|
|
46
46
|
it('has shortcut for GET', async () => {
|
|
47
47
|
let fetch = spy(async () => ({
|
|
48
|
-
status: 200,
|
|
49
48
|
async json() {
|
|
50
49
|
return { answer: '1' }
|
|
51
|
-
}
|
|
50
|
+
},
|
|
51
|
+
status: 200
|
|
52
52
|
}))
|
|
53
53
|
|
|
54
54
|
expect(await get('/a', { headers: { a: 1 } }, fetch)).toEqual({ answer: '1' })
|
|
@@ -56,8 +56,8 @@ it('has shortcut for GET', async () => {
|
|
|
56
56
|
[
|
|
57
57
|
'/a',
|
|
58
58
|
{
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
headers: { a: 1 },
|
|
60
|
+
method: 'GET'
|
|
61
61
|
}
|
|
62
62
|
]
|
|
63
63
|
])
|
|
@@ -70,8 +70,8 @@ it('has shortcut for POST', async () => {
|
|
|
70
70
|
[
|
|
71
71
|
'/a',
|
|
72
72
|
{
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
headers: { a: 1 },
|
|
74
|
+
method: 'POST'
|
|
75
75
|
}
|
|
76
76
|
]
|
|
77
77
|
])
|
|
@@ -84,8 +84,8 @@ it('has shortcut for PUT', async () => {
|
|
|
84
84
|
[
|
|
85
85
|
'/a',
|
|
86
86
|
{
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
headers: { a: 1 },
|
|
88
|
+
method: 'PUT'
|
|
89
89
|
}
|
|
90
90
|
]
|
|
91
91
|
])
|
|
@@ -98,8 +98,8 @@ it('has shortcut for PATCH', async () => {
|
|
|
98
98
|
[
|
|
99
99
|
'/a',
|
|
100
100
|
{
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
headers: { a: 1 },
|
|
102
|
+
method: 'PATCH'
|
|
103
103
|
}
|
|
104
104
|
]
|
|
105
105
|
])
|
|
@@ -112,8 +112,8 @@ it('has shortcut for DELETE', async () => {
|
|
|
112
112
|
[
|
|
113
113
|
'/a',
|
|
114
114
|
{
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
headers: { a: 1 },
|
|
116
|
+
method: 'DELETE'
|
|
117
117
|
}
|
|
118
118
|
]
|
|
119
119
|
])
|
package/server/index.d.ts
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
BaseServer,
|
|
3
|
+
type BaseServerOptions,
|
|
4
|
+
type Logger
|
|
5
|
+
} from '../base-server/index.js'
|
|
4
6
|
|
|
5
7
|
export interface LoggerOptions {
|
|
6
|
-
/**
|
|
7
|
-
* Logger message format.
|
|
8
|
-
*/
|
|
9
|
-
type?: 'human' | 'json'
|
|
10
|
-
|
|
11
8
|
/**
|
|
12
9
|
* Stream to be used by logger to write log.
|
|
13
10
|
*/
|
|
14
11
|
stream?: {
|
|
15
|
-
write(str: string): void
|
|
16
|
-
|
|
17
12
|
/**
|
|
18
13
|
* Used by pino to synchronously write log messages on application failure.
|
|
19
14
|
*/
|
|
20
15
|
flushSync?(): void
|
|
16
|
+
|
|
17
|
+
write(str: string): void
|
|
21
18
|
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Logger message format.
|
|
22
|
+
*/
|
|
23
|
+
type?: 'human' | 'json'
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export interface ServerOptions extends BaseServerOptions {
|
|
@@ -75,6 +77,20 @@ export interface ServerOptions extends BaseServerOptions {
|
|
|
75
77
|
* ```
|
|
76
78
|
*/
|
|
77
79
|
export class Server<Headers extends object = {}> extends BaseServer<Headers> {
|
|
80
|
+
/**
|
|
81
|
+
* Server options.
|
|
82
|
+
*
|
|
83
|
+
* ```js
|
|
84
|
+
* console.log('Server options', server.options.subprotocol)
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
options: ServerOptions
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param opts Server options.
|
|
91
|
+
*/
|
|
92
|
+
constructor(opts: ServerOptions)
|
|
93
|
+
|
|
78
94
|
/**
|
|
79
95
|
* Load options from command-line arguments and/or environment.
|
|
80
96
|
*
|
|
@@ -97,20 +113,6 @@ export class Server<Headers extends object = {}> extends BaseServer<Headers> {
|
|
|
97
113
|
defaults: ServerOptions
|
|
98
114
|
): ServerOptions
|
|
99
115
|
|
|
100
|
-
/**
|
|
101
|
-
* @param opts Server options.
|
|
102
|
-
*/
|
|
103
|
-
constructor(opts: ServerOptions)
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Server options.
|
|
107
|
-
*
|
|
108
|
-
* ```js
|
|
109
|
-
* console.log('Server options', server.options.subprotocol)
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
options: ServerOptions
|
|
113
|
-
|
|
114
116
|
/**
|
|
115
117
|
* Load module creators and apply to the server. By default, it will load
|
|
116
118
|
* files from `modules/*`.
|
|
@@ -121,5 +123,5 @@ export class Server<Headers extends object = {}> extends BaseServer<Headers> {
|
|
|
121
123
|
*
|
|
122
124
|
* @param files Pattern for module files.
|
|
123
125
|
*/
|
|
124
|
-
autoloadModules(files?: string
|
|
126
|
+
autoloadModules(files?: string | string[]): Promise<void>
|
|
125
127
|
}
|
package/server/index.js
CHANGED
|
@@ -1,80 +1,60 @@
|
|
|
1
|
+
import glob from 'fast-glob'
|
|
1
2
|
import { join, relative } from 'path'
|
|
2
3
|
import pico from 'picocolors'
|
|
3
|
-
import glob from 'fast-glob'
|
|
4
4
|
|
|
5
|
-
import { createReporter } from '../create-reporter/index.js'
|
|
6
5
|
import { BaseServer } from '../base-server/index.js'
|
|
7
|
-
import {
|
|
6
|
+
import { createReporter } from '../create-reporter/index.js'
|
|
7
|
+
import { loadOptions, number, oneOf } from '../options-loader/index.js'
|
|
8
8
|
|
|
9
9
|
let cliOptionsSpec = {
|
|
10
|
+
envPrefix: 'LOGUX',
|
|
11
|
+
examples: [
|
|
12
|
+
'$0 --port 31337 --host 127.0.0.1',
|
|
13
|
+
'LOGUX_PORT=1337 LOGUX_HOST=127.0.0.1 $0'
|
|
14
|
+
],
|
|
10
15
|
options: {
|
|
16
|
+
backend: {
|
|
17
|
+
description: 'Backend to process actions'
|
|
18
|
+
},
|
|
19
|
+
cert: {
|
|
20
|
+
description: 'Path to SSL certificate'
|
|
21
|
+
},
|
|
22
|
+
controlMask: {
|
|
23
|
+
description: 'CIDR masks of control servers'
|
|
24
|
+
},
|
|
25
|
+
controlSecret: {
|
|
26
|
+
description: 'Secret to control Logux server'
|
|
27
|
+
},
|
|
11
28
|
host: {
|
|
12
29
|
alias: 'h',
|
|
13
30
|
description: 'Host to bind server'
|
|
14
31
|
},
|
|
15
|
-
port: {
|
|
16
|
-
alias: 'p',
|
|
17
|
-
description: 'Port to bind server',
|
|
18
|
-
parse: number
|
|
19
|
-
},
|
|
20
32
|
key: {
|
|
21
33
|
description: 'Path to SSL key'
|
|
22
34
|
},
|
|
23
|
-
cert: {
|
|
24
|
-
description: 'Path to SSL certificate'
|
|
25
|
-
},
|
|
26
|
-
supports: {
|
|
27
|
-
description: 'Range of supported client subprotocols'
|
|
28
|
-
},
|
|
29
|
-
subprotocol: {
|
|
30
|
-
description: 'Server subprotocol'
|
|
31
|
-
},
|
|
32
35
|
logger: {
|
|
33
36
|
alias: 'l',
|
|
34
37
|
description: 'Logger type',
|
|
35
38
|
parse: value => oneOf(['human', 'json'], value)
|
|
36
39
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
description: 'Secret to control Logux server'
|
|
42
|
-
},
|
|
43
|
-
controlMask: {
|
|
44
|
-
description: 'CIDR masks of control servers'
|
|
40
|
+
port: {
|
|
41
|
+
alias: 'p',
|
|
42
|
+
description: 'Port to bind server',
|
|
43
|
+
parse: number
|
|
45
44
|
},
|
|
46
45
|
redis: {
|
|
47
46
|
description: 'Redis URL for Logux Server Pro scaling'
|
|
47
|
+
},
|
|
48
|
+
subprotocol: {
|
|
49
|
+
description: 'Server subprotocol'
|
|
50
|
+
},
|
|
51
|
+
supports: {
|
|
52
|
+
description: 'Range of supported client subprotocols'
|
|
48
53
|
}
|
|
49
|
-
}
|
|
50
|
-
envPrefix: 'LOGUX',
|
|
51
|
-
examples: [
|
|
52
|
-
'$0 --port 31337 --host 127.0.0.1',
|
|
53
|
-
'LOGUX_PORT=1337 LOGUX_HOST=127.0.0.1 $0'
|
|
54
|
-
]
|
|
54
|
+
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export class Server extends BaseServer {
|
|
58
|
-
static loadOptions(process, defaults) {
|
|
59
|
-
let [help, options] = loadOptions(
|
|
60
|
-
cliOptionsSpec,
|
|
61
|
-
process,
|
|
62
|
-
defaults.root ? { path: join(defaults.root, '.env') } : undefined
|
|
63
|
-
)
|
|
64
|
-
if (help) {
|
|
65
|
-
process.stdout.write(help + '\n')
|
|
66
|
-
return process.exit(0)
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
return Object.assign(defaults, options)
|
|
70
|
-
} catch (e) {
|
|
71
|
-
process.stderr.write(
|
|
72
|
-
`${pico.bgRed(pico.black(' FATAL '))} ${e.message}\n`
|
|
73
|
-
)
|
|
74
|
-
return process.exit(1)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
58
|
constructor(opts = {}) {
|
|
79
59
|
if (!opts.logger) {
|
|
80
60
|
opts.logger = 'human'
|
|
@@ -122,11 +102,22 @@ export class Server extends BaseServer {
|
|
|
122
102
|
})
|
|
123
103
|
}
|
|
124
104
|
|
|
125
|
-
|
|
105
|
+
static loadOptions(process, defaults) {
|
|
106
|
+
let [help, options] = loadOptions(
|
|
107
|
+
cliOptionsSpec,
|
|
108
|
+
process,
|
|
109
|
+
defaults.root ? { path: join(defaults.root, '.env') } : undefined
|
|
110
|
+
)
|
|
111
|
+
if (help) {
|
|
112
|
+
process.stdout.write(help + '\n')
|
|
113
|
+
return process.exit(0)
|
|
114
|
+
}
|
|
126
115
|
try {
|
|
127
|
-
return
|
|
128
|
-
} catch (
|
|
129
|
-
|
|
116
|
+
return Object.assign(defaults, options)
|
|
117
|
+
} catch (e) {
|
|
118
|
+
process.stderr.write(
|
|
119
|
+
`${pico.bgRed(pico.black(' FATAL '))} ${e.message}\n`
|
|
120
|
+
)
|
|
130
121
|
return process.exit(1)
|
|
131
122
|
}
|
|
132
123
|
}
|
|
@@ -135,8 +126,8 @@ export class Server extends BaseServer {
|
|
|
135
126
|
files = ['modules/*/index.js', 'modules/*.js', '!**/*.{test,spec}.js']
|
|
136
127
|
) {
|
|
137
128
|
let matches = await glob(files, {
|
|
138
|
-
cwd: this.options.root,
|
|
139
129
|
absolute: true,
|
|
130
|
+
cwd: this.options.root,
|
|
140
131
|
onlyFiles: true
|
|
141
132
|
})
|
|
142
133
|
|
|
@@ -158,4 +149,13 @@ export class Server extends BaseServer {
|
|
|
158
149
|
})
|
|
159
150
|
)
|
|
160
151
|
}
|
|
152
|
+
|
|
153
|
+
async listen(...args) {
|
|
154
|
+
try {
|
|
155
|
+
return BaseServer.prototype.listen.apply(this, args)
|
|
156
|
+
} catch (err) {
|
|
157
|
+
this.emitter.emit('report', 'error', { err })
|
|
158
|
+
return process.exit(1)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
161
|
}
|