geonix 1.23.3 → 1.23.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/package.json +4 -4
- package/src/Gateway.js +4 -4
- package/src/Util.js +10 -0
- package/test/gateway.js +25 -24
- package/test/ws_auth.js +21 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geonix",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "",
|
|
6
6
|
"bin": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"cookie-parser": "1.4.7",
|
|
20
|
-
"express": "4.21.
|
|
20
|
+
"express": "^4.21.2",
|
|
21
21
|
"express-async-errors": "3.1.1",
|
|
22
22
|
"express-ws": "5.0.2",
|
|
23
23
|
"nats": "2.28.2",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"registry": "https://registry.npmjs.org/"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"eslint": "^9.
|
|
31
|
+
"eslint": "^9.36.0",
|
|
32
32
|
"typescript": "^5.5.4"
|
|
33
33
|
}
|
|
34
|
-
}
|
|
34
|
+
}
|
package/src/Gateway.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { connection } from "./Connection.js";
|
|
2
2
|
import { registry } from "./Registry.js";
|
|
3
|
-
import { createTCPServer, GeonixVersion, picoid, proxyHttp, sleep } from "./Util.js";
|
|
3
|
+
import { cleanupWebsocketUrl, createTCPServer, GeonixVersion, picoid, proxyHttp, sleep } from "./Util.js";
|
|
4
4
|
import express, { Router } from "express";
|
|
5
5
|
import { Request } from "./Request.js";
|
|
6
6
|
import { HEALTH_CHECK_ENDPOINT } from "./WebServer.js";
|
|
@@ -401,10 +401,10 @@ export class Gateway {
|
|
|
401
401
|
|
|
402
402
|
if (verb === "ws") {
|
|
403
403
|
router.ws(uri, (ws, req) => {
|
|
404
|
-
|
|
404
|
+
let target = cleanupWebsocketUrl(`ws://${backend}${req.originalUrl}`);
|
|
405
405
|
|
|
406
|
-
logger.debug("proxy.web.ws.to:",
|
|
407
|
-
this.#proxyWebsocketOverNats(
|
|
406
|
+
logger.debug("proxy.web.ws.to:", target);
|
|
407
|
+
this.#proxyWebsocketOverNats(target, ws, req);
|
|
408
408
|
});
|
|
409
409
|
} else {
|
|
410
410
|
router[verb](uri, async (req, res, _next) => {
|
package/src/Util.js
CHANGED
|
@@ -413,4 +413,14 @@ export function deepMerge(target, ...source) {
|
|
|
413
413
|
}
|
|
414
414
|
|
|
415
415
|
return target;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export function cleanupWebsocketUrl(url) {
|
|
419
|
+
try {
|
|
420
|
+
const parsed = new URL(url);
|
|
421
|
+
parsed.pathname = parsed.pathname.replace(/\/\.websocket$/, "");
|
|
422
|
+
return parsed.toString();
|
|
423
|
+
} catch {
|
|
424
|
+
return url;
|
|
425
|
+
}
|
|
416
426
|
}
|
package/test/gateway.js
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import { Gateway, Service, streamToBuffer } from "../exports.js";
|
|
2
2
|
import { parseMultipart } from "../src/Util.js";
|
|
3
3
|
|
|
4
|
-
class TestService extends Service {
|
|
4
|
+
// class TestService extends Service {
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
// "GET /"(req, res) {
|
|
7
|
+
// res.send("Hello World");
|
|
8
|
+
// }
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// async "POST /upload"(req, res) {
|
|
11
|
+
// const parts = await parseMultipart(req, { useMemory: false });
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
// for (const part of parts) {
|
|
14
|
+
// console.log(part.body);
|
|
15
|
+
// }
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
// res.send("OK");
|
|
18
|
+
// }
|
|
19
19
|
|
|
20
|
-
}
|
|
20
|
+
// }
|
|
21
21
|
|
|
22
|
-
TestService.start({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
Gateway.start({
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
22
|
+
// TestService.start({
|
|
23
|
+
// middleware: {
|
|
24
|
+
// raw: true,
|
|
25
|
+
// json: false,
|
|
26
|
+
// cookies: false,
|
|
27
|
+
// }
|
|
28
|
+
// });
|
|
29
|
+
// Gateway.start({
|
|
30
|
+
// beforeRequest: (req, res) => {
|
|
31
|
+
// res.set("X-Test", "Test");
|
|
32
|
+
// }
|
|
33
|
+
// });
|
|
34
|
+
Gateway.start();
|
package/test/ws_auth.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Gateway, ServeStatic, Service } from "../exports.js";
|
|
2
|
+
|
|
3
|
+
class ServiceFirst extends Service {
|
|
4
|
+
"WS /ws/first" = (ws) => {
|
|
5
|
+
ws.on("message", (message) => {
|
|
6
|
+
ws.send("first:" + message);
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class ServiceSecond extends Service {
|
|
12
|
+
"WS /ws/second" = (ws) => {
|
|
13
|
+
ws.on("message", (message) => {
|
|
14
|
+
ws.send("second:" + message);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Gateway.start();
|
|
20
|
+
ServiceFirst.start();
|
|
21
|
+
ServiceSecond.start();
|