allserver 1.3.0 → 2.0.0
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 +1 -1
- package/package.json +33 -5
- package/src/client/HttpClientTransport.js +3 -2
- package/src/server/HttpTransport.js +16 -10
package/README.md
CHANGED
|
@@ -145,7 +145,7 @@ Please note, that Allserver depends only on a single tiny npm module [`stampit`]
|
|
|
145
145
|
The default `HttpTransport` is using the [`micro`](http://npmjs.com/package/micro) npm module as an optional dependency.
|
|
146
146
|
|
|
147
147
|
```shell
|
|
148
|
-
npm i allserver micro
|
|
148
|
+
npm i allserver micro@10
|
|
149
149
|
```
|
|
150
150
|
|
|
151
151
|
Alternatively, you can embed Allserver into your existing Express.js application:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "allserver",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Multi-protocol simple RPC server and [optional] client. Boilerplate-less. Opinionated. Minimalistic. DX-first.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,16 +31,44 @@
|
|
|
31
31
|
"homepage": "https://github.com/flash-oss/allserver",
|
|
32
32
|
"author": "Vasyl Boroviak",
|
|
33
33
|
"license": "MIT",
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@grpc/grpc-js": "^1.1.7",
|
|
36
|
+
"@grpc/proto-loader": "^0.7.5",
|
|
37
|
+
"bullmq": "^3.10.1",
|
|
38
|
+
"express": "^4.18.2",
|
|
39
|
+
"micro": "^10.0.1",
|
|
40
|
+
"node-fetch": "^2.6.9"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"@grpc/grpc-js": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
46
|
+
"@grpc/proto-loader": {
|
|
47
|
+
"optional": true
|
|
48
|
+
},
|
|
49
|
+
"bullmq": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"express": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"micro": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"node-fetch": {
|
|
59
|
+
"optional": true
|
|
60
|
+
}
|
|
61
|
+
},
|
|
34
62
|
"devDependencies": {
|
|
35
63
|
"@grpc/grpc-js": "^1.1.7",
|
|
36
|
-
"@grpc/proto-loader": "^0.
|
|
37
|
-
"bullmq": "^3.
|
|
64
|
+
"@grpc/proto-loader": "^0.7.5",
|
|
65
|
+
"bullmq": "^3.10.1",
|
|
38
66
|
"eslint": "^7.9.0",
|
|
39
67
|
"express": "^4.18.2",
|
|
40
68
|
"lambda-local": "^1.7.3",
|
|
41
|
-
"micro": "^
|
|
69
|
+
"micro": "^10.0.1",
|
|
42
70
|
"mocha": "^10.2.0",
|
|
43
|
-
"node-fetch": "^2.6.
|
|
71
|
+
"node-fetch": "^2.6.9",
|
|
44
72
|
"nyc": "^15.1.0",
|
|
45
73
|
"prettier": "^2.1.1"
|
|
46
74
|
},
|
|
@@ -5,7 +5,7 @@ module.exports = require("./ClientTransport").compose({
|
|
|
5
5
|
|
|
6
6
|
props: {
|
|
7
7
|
// eslint-disable-next-line no-undef
|
|
8
|
-
fetch: (typeof
|
|
8
|
+
fetch: (typeof globalThis !== "undefined" && globalThis.fetch) || require("node-fetch"),
|
|
9
9
|
headers: {
|
|
10
10
|
"Content-Type": "application/json; charset=utf-8",
|
|
11
11
|
},
|
|
@@ -31,7 +31,8 @@ module.exports = require("./ClientTransport").compose({
|
|
|
31
31
|
response = await this.fetch(this.uri + procedureName, http);
|
|
32
32
|
http.response = response;
|
|
33
33
|
} catch (err) {
|
|
34
|
-
if (err.code === "ECONNREFUSED"
|
|
34
|
+
if (err.code === "ECONNREFUSED" || (err.cause && err.cause.code === "ECONNREFUSED"))
|
|
35
|
+
err.noNetToServer = true;
|
|
35
36
|
throw err;
|
|
36
37
|
}
|
|
37
38
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const http = require("http");
|
|
1
2
|
const { parse: parseUrl, URLSearchParams } = require("url");
|
|
2
3
|
|
|
3
4
|
module.exports = require("./Transport").compose({
|
|
@@ -39,22 +40,27 @@ module.exports = require("./Transport").compose({
|
|
|
39
40
|
},
|
|
40
41
|
|
|
41
42
|
startServer(defaultCtx) {
|
|
42
|
-
this.server =
|
|
43
|
-
|
|
43
|
+
this.server = new http.Server(
|
|
44
|
+
this.micro.serve(async (req, res) => {
|
|
45
|
+
const ctx = { ...defaultCtx, http: { req, res, url: parseUrl(req.url) } };
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
ctx.http.query = {};
|
|
48
|
+
if (ctx.http.url.query) {
|
|
49
|
+
for (const [key, value] of new URLSearchParams(ctx.http.url.query).entries()) {
|
|
50
|
+
ctx.http.query[key] = value;
|
|
51
|
+
}
|
|
49
52
|
}
|
|
50
|
-
}
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
await this._handleRequest(ctx);
|
|
55
|
+
})
|
|
56
|
+
);
|
|
54
57
|
return new Promise((r) => this.server.listen(this.port, r));
|
|
55
58
|
},
|
|
56
59
|
stopServer() {
|
|
57
|
-
return new Promise((r) =>
|
|
60
|
+
return new Promise((r) => {
|
|
61
|
+
if (this.server.closeIdleConnections) this.server.closeIdleConnections();
|
|
62
|
+
this.server.close(r);
|
|
63
|
+
});
|
|
58
64
|
},
|
|
59
65
|
|
|
60
66
|
getProcedureName(ctx) {
|