objective-http 1.2.3 → 1.2.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 +11 -11
- package/package.json +1 -1
- package/src/js/bun/Bunttp.js +6 -7
- package/src/js/index.js +1 -1
- package/src/js/server/Server.js +6 -6
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ There are all `Server` classes feature.
|
|
|
8
8
|
Your endpoints must implement `Endpoint` class interface (`route()` and `async handle(request)` methods).
|
|
9
9
|
|
|
10
10
|
```javascript
|
|
11
|
-
const
|
|
11
|
+
const createServerFunction = require('node:http').createServer;
|
|
12
12
|
|
|
13
13
|
const {
|
|
14
14
|
Server,
|
|
@@ -34,7 +34,7 @@ new LoggedServer(
|
|
|
34
34
|
{port: server_port},
|
|
35
35
|
new LoggedInputRequest(new JsonInputRequest(new InputRequest()), console),
|
|
36
36
|
new LoggedOutputResponse(new JsonOutputResponse(new OutputResponse()), console),
|
|
37
|
-
|
|
37
|
+
createServerFunction
|
|
38
38
|
),
|
|
39
39
|
console
|
|
40
40
|
).start();
|
|
@@ -74,8 +74,8 @@ class MyEndpoint {
|
|
|
74
74
|
## Client
|
|
75
75
|
|
|
76
76
|
```javascript
|
|
77
|
-
const
|
|
78
|
-
|
|
77
|
+
const requestFunction = require('node:http').request;
|
|
78
|
+
|
|
79
79
|
const {
|
|
80
80
|
OutputRequest,
|
|
81
81
|
InputResponse
|
|
@@ -122,7 +122,7 @@ And you should replace `node:http` package with `objective-http.bun.bunttp` in y
|
|
|
122
122
|
It should work with `node` and `bun`:
|
|
123
123
|
|
|
124
124
|
```javascript
|
|
125
|
-
const
|
|
125
|
+
const createServerFunction = require('node:http').createServer;
|
|
126
126
|
|
|
127
127
|
const {
|
|
128
128
|
Server,
|
|
@@ -148,7 +148,7 @@ new LoggedServer(
|
|
|
148
148
|
{port: server_port},
|
|
149
149
|
new LoggedInputRequest(new JsonInputRequest(new InputRequest()), console),
|
|
150
150
|
new LoggedOutputResponse(new JsonOutputResponse(new OutputResponse()), console),
|
|
151
|
-
|
|
151
|
+
createServerFunction
|
|
152
152
|
),
|
|
153
153
|
console
|
|
154
154
|
).start()
|
|
@@ -158,7 +158,7 @@ In order for the code to be executed only by `bun` (with `Bun API` inside), you
|
|
|
158
158
|
`bun` package redeclare only `InputRequest` and `OutputResponse` classes. Other classes taken from `server` package.
|
|
159
159
|
|
|
160
160
|
```javascript
|
|
161
|
-
const
|
|
161
|
+
const createServerFunction = require('objective-http').bun.bunttp.createServer;
|
|
162
162
|
|
|
163
163
|
const {
|
|
164
164
|
Server,
|
|
@@ -181,8 +181,8 @@ const {
|
|
|
181
181
|
It should work with `node` and `bun`:
|
|
182
182
|
|
|
183
183
|
```javascript
|
|
184
|
-
const
|
|
185
|
-
|
|
184
|
+
const requestFunction = require('node:http').request;
|
|
185
|
+
|
|
186
186
|
const {
|
|
187
187
|
OutputRequest,
|
|
188
188
|
InputResponse
|
|
@@ -200,8 +200,8 @@ await (new OutputRequest(new InputResponse(), requestFunction)
|
|
|
200
200
|
In order for the code to be executed only by `bun`, you need to make changes to the import block.
|
|
201
201
|
|
|
202
202
|
```javascript
|
|
203
|
-
const
|
|
204
|
-
|
|
203
|
+
const requestFunction = require('objective-http').bun.bunttp.request;
|
|
204
|
+
|
|
205
205
|
const {
|
|
206
206
|
OutputRequest,
|
|
207
207
|
InputResponse
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"objective-http","version":"1.2.
|
|
1
|
+
{"name":"objective-http","version":"1.2.5","description":"Proxy classes for creating a http server","keywords":["web","web-server","http","http-server","oop"],"author":{"name":"volatilization","email":"volatilization@yandex.ru"},"repository":{"url":"git+https://github.com/volatilization/objective-http.git"},"license":"LGPL-3.0-only","main":"src/js/index.js"}
|
package/src/js/bun/Bunttp.js
CHANGED
|
@@ -8,21 +8,20 @@ module.exports = class Bunttp {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
createServer(cb) {
|
|
11
|
-
|
|
12
|
-
return this;
|
|
11
|
+
return new Bunttp({fetch: cb});
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
listen(options, cb) {
|
|
16
|
-
this.#serverConfig
|
|
17
|
-
|
|
15
|
+
const config = {...this.#serverConfig, port: options.port};
|
|
16
|
+
const server = Bun.serve(config);
|
|
18
17
|
cb();
|
|
19
|
-
return
|
|
18
|
+
return new Bunttp(config, server);
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
close(cb) {
|
|
23
|
-
this.#server.stop();
|
|
22
|
+
const server = this.#server.stop();
|
|
24
23
|
cb();
|
|
25
|
-
return this;
|
|
24
|
+
return new Bunttp(this.#serverConfig, server);
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
request = fetch;
|
package/src/js/index.js
CHANGED
|
@@ -2,7 +2,7 @@ module.exports = {
|
|
|
2
2
|
server: require('./server'),
|
|
3
3
|
client: require('./client'),
|
|
4
4
|
bun: {
|
|
5
|
-
server: {...require('./server'), ...require('./bun
|
|
5
|
+
server: {...require('./server'), ...require('./bun').server},
|
|
6
6
|
client: {...require('./client'), ...require('./bun').client},
|
|
7
7
|
bunttp: require('./bun').bunttp
|
|
8
8
|
}
|
package/src/js/server/Server.js
CHANGED
|
@@ -3,20 +3,20 @@ module.exports = class Server {
|
|
|
3
3
|
#options;
|
|
4
4
|
#request;
|
|
5
5
|
#response;
|
|
6
|
-
#
|
|
6
|
+
#createServerFunction;
|
|
7
7
|
#server;
|
|
8
8
|
|
|
9
|
-
constructor(endpoints, options, request, response,
|
|
9
|
+
constructor(endpoints, options, request, response, createServerFunction, server) {
|
|
10
10
|
this.#endpoints = endpoints;
|
|
11
11
|
this.#options = options;
|
|
12
12
|
this.#request = request;
|
|
13
13
|
this.#response = response;
|
|
14
|
-
this.#
|
|
14
|
+
this.#createServerFunction = createServerFunction;
|
|
15
15
|
this.#server = server;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
start() {
|
|
19
|
-
const server = this.#
|
|
19
|
+
const server = this.#createServerFunction(async (requestStream, responseStream) => {
|
|
20
20
|
try {
|
|
21
21
|
return await (this.#response
|
|
22
22
|
.copy(await this.#endpoints
|
|
@@ -53,7 +53,7 @@ module.exports = class Server {
|
|
|
53
53
|
this.#options,
|
|
54
54
|
this.#request,
|
|
55
55
|
this.#response,
|
|
56
|
-
this.#
|
|
56
|
+
this.#createServerFunction,
|
|
57
57
|
server));
|
|
58
58
|
}
|
|
59
59
|
);
|
|
@@ -68,7 +68,7 @@ module.exports = class Server {
|
|
|
68
68
|
this.#options,
|
|
69
69
|
this.#request,
|
|
70
70
|
this.#response,
|
|
71
|
-
this.#
|
|
71
|
+
this.#createServerFunction))
|
|
72
72
|
);
|
|
73
73
|
});
|
|
74
74
|
}
|