geonix 1.10.8 → 1.10.10
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/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/Gateway.js +18 -3
- package/test/package.json +16 -0
- package/test/stream.js +38 -0
package/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/Gateway.js
CHANGED
|
@@ -27,12 +27,18 @@ const stats = {
|
|
|
27
27
|
debug_requests: 0
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
const defaultOpts = {
|
|
31
|
+
afterRequest: (req, res) => { },
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
30
35
|
export class Gateway {
|
|
31
36
|
|
|
32
|
-
static start() {
|
|
33
|
-
return new Gateway()
|
|
37
|
+
static start(opts) {
|
|
38
|
+
return new Gateway(opts)
|
|
34
39
|
}
|
|
35
40
|
|
|
41
|
+
#opts = defaultOpts
|
|
36
42
|
#api = express()
|
|
37
43
|
#router = (req, res, next) => next()
|
|
38
44
|
#activeServers = []
|
|
@@ -44,9 +50,11 @@ export class Gateway {
|
|
|
44
50
|
|
|
45
51
|
#registry = {}
|
|
46
52
|
|
|
47
|
-
constructor() {
|
|
53
|
+
constructor(opts) {
|
|
48
54
|
expressWs(this.#api)
|
|
49
55
|
|
|
56
|
+
this.#opts = { ...this.#opts, ...opts }
|
|
57
|
+
|
|
50
58
|
this.#start()
|
|
51
59
|
}
|
|
52
60
|
|
|
@@ -92,6 +100,13 @@ export class Gateway {
|
|
|
92
100
|
next()
|
|
93
101
|
})
|
|
94
102
|
|
|
103
|
+
this.#api.use((req, res, next) => {
|
|
104
|
+
if (this.#opts.afterRequest) {
|
|
105
|
+
this.#opts.afterRequest(req, res)
|
|
106
|
+
}
|
|
107
|
+
next()
|
|
108
|
+
})
|
|
109
|
+
|
|
95
110
|
// config
|
|
96
111
|
this.#api.disable('x-powered-by')
|
|
97
112
|
this.#api.disable('etag')
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "test",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "stream.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"geonix": "file:.."
|
|
15
|
+
}
|
|
16
|
+
}
|
package/test/stream.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto'
|
|
2
|
+
import { Stream, getReadable, connection } from 'geonix'
|
|
3
|
+
import { createWriteStream, readFileSync } from 'node:fs'
|
|
4
|
+
import { createHash } from 'node:crypto'
|
|
5
|
+
import { pipeline } from 'node:stream/promises'
|
|
6
|
+
|
|
7
|
+
await connection.waitUntilReady()
|
|
8
|
+
|
|
9
|
+
const hash = data => createHash('sha512').update(data).digest('base64')
|
|
10
|
+
|
|
11
|
+
const PAYLOAD_SIZE = 1024 * 1024 * 1024
|
|
12
|
+
const TEMP_FILE = '/tmp/geonix.stream_test'
|
|
13
|
+
|
|
14
|
+
console.time('test')
|
|
15
|
+
try {
|
|
16
|
+
const payload = randomBytes(PAYLOAD_SIZE)
|
|
17
|
+
const sourceHash = hash(payload)
|
|
18
|
+
|
|
19
|
+
const source = await getReadable(Stream(payload))
|
|
20
|
+
const dest = createWriteStream(TEMP_FILE)
|
|
21
|
+
|
|
22
|
+
await pipeline(source, dest)
|
|
23
|
+
|
|
24
|
+
const check = readFileSync(TEMP_FILE)
|
|
25
|
+
const destHash = hash(check)
|
|
26
|
+
|
|
27
|
+
if (sourceHash == destHash) {
|
|
28
|
+
console.log('MATCH')
|
|
29
|
+
} else {
|
|
30
|
+
console.error('Destination does not match the source!')
|
|
31
|
+
console.log(payload)
|
|
32
|
+
console.log(check)
|
|
33
|
+
}
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.error(e)
|
|
36
|
+
} finally {
|
|
37
|
+
console.timeEnd('test')
|
|
38
|
+
}
|