@superhero/http-server 4.2.7 → 4.3.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/index.js +8 -18
- package/index.test.js +7 -7
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ const locator = new Locator();
|
|
|
53
53
|
const router = new Router(locator);
|
|
54
54
|
|
|
55
55
|
// Instantiate the server
|
|
56
|
-
const server = HttpServer(
|
|
56
|
+
const server = new HttpServer(router);
|
|
57
57
|
|
|
58
58
|
// Register the route dispatcher service
|
|
59
59
|
locator.set('hello-dispatcher', {
|
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import View from '@superhero/http-server/view'
|
|
2
2
|
import Router from '@superhero/router'
|
|
3
|
+
import Log from '@superhero/log'
|
|
3
4
|
import http from 'node:http'
|
|
4
5
|
import https from 'node:https'
|
|
5
6
|
import http2 from 'node:http2'
|
|
@@ -18,6 +19,8 @@ export function locate(locator)
|
|
|
18
19
|
*/
|
|
19
20
|
export default class HttpServer
|
|
20
21
|
{
|
|
22
|
+
log = new Log({ label: '[HTTP:SERVER]' })
|
|
23
|
+
|
|
21
24
|
#sessions = new Set()
|
|
22
25
|
|
|
23
26
|
constructor(router)
|
|
@@ -102,7 +105,7 @@ export default class HttpServer
|
|
|
102
105
|
|
|
103
106
|
session.on('close', () => this.log.info`${session.id} ⇣ closed`)
|
|
104
107
|
session.on('close', () => this.#sessions.delete(session))
|
|
105
|
-
session.on('error', this.log.error)
|
|
108
|
+
session.on('error', (error) => this.log.fail`${error}`)
|
|
106
109
|
this.#sessions.add(session)
|
|
107
110
|
this.log.info`${session.id} ⇡ session`
|
|
108
111
|
}
|
|
@@ -382,7 +385,7 @@ export default class HttpServer
|
|
|
382
385
|
#onRouterDispatchRejected(session, reason)
|
|
383
386
|
{
|
|
384
387
|
session.view.presentError(reason.cause)
|
|
385
|
-
this.log.
|
|
388
|
+
this.log.fail`${reason}`
|
|
386
389
|
}
|
|
387
390
|
|
|
388
391
|
#onDownstreamError(reason)
|
|
@@ -390,7 +393,7 @@ export default class HttpServer
|
|
|
390
393
|
const error = new Error('Downstream error')
|
|
391
394
|
error.code = 'E_HTTP_SERVER_DOWNSTREAM_ERROR'
|
|
392
395
|
error.cause = reason
|
|
393
|
-
this.log.error
|
|
396
|
+
this.log.fail`${error}`
|
|
394
397
|
}
|
|
395
398
|
|
|
396
399
|
#onUpstreamError(reason)
|
|
@@ -398,7 +401,7 @@ export default class HttpServer
|
|
|
398
401
|
const error = new Error('Upstream error')
|
|
399
402
|
error.code = 'E_HTTP_SERVER_UPSTREAM_ERROR'
|
|
400
403
|
error.cause = reason
|
|
401
|
-
this.log.error
|
|
404
|
+
this.log.fail`${error}`
|
|
402
405
|
}
|
|
403
406
|
|
|
404
407
|
#onServerError(reason)
|
|
@@ -406,19 +409,6 @@ export default class HttpServer
|
|
|
406
409
|
const error = new Error('Server error')
|
|
407
410
|
error.code = 'E_HTTP_SERVER_ERROR'
|
|
408
411
|
error.cause = reason
|
|
409
|
-
this.log.error
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// Will make the log methods availible to overwrite
|
|
413
|
-
// if a custom logging is desired.
|
|
414
|
-
log =
|
|
415
|
-
{
|
|
416
|
-
label : '[HTTP:SERVER] ⇢ ',
|
|
417
|
-
simple : (template, ...args) => this.log.label + template.reduce((result, part, i) => result + args[i - 1] + part),
|
|
418
|
-
colors : (template, ...args) => '\x1b[90m\x1b[1m\x1b[2m' + this.log.label + '\x1b[22m' + template.reduce((result, part, i) => result + '\x1b[96m\x1b[2m' + args[i - 1] + '\x1b[90m' + part) + '\x1b[0m',
|
|
419
|
-
format : (...args) => this.log.colors(...args),
|
|
420
|
-
info : (...args) => console.info (this.log.format(...args)),
|
|
421
|
-
warning : (...args) => console.warn (this.log.format(...args)),
|
|
422
|
-
error : (...args) => console.error (this.log.format`failure`, ...args)
|
|
412
|
+
this.log.fail`${error}`
|
|
423
413
|
}
|
|
424
414
|
}
|
package/index.test.js
CHANGED
|
@@ -33,7 +33,7 @@ suite('@superhero/http-server', () =>
|
|
|
33
33
|
})
|
|
34
34
|
|
|
35
35
|
server = locator.locate('@superhero/http-server')
|
|
36
|
-
server.log.
|
|
36
|
+
server.log.config.mute = true
|
|
37
37
|
})
|
|
38
38
|
|
|
39
39
|
afterEach (() =>
|
|
@@ -327,12 +327,12 @@ suite('@superhero/http-server', () =>
|
|
|
327
327
|
|
|
328
328
|
let errorLoggerCalled = false
|
|
329
329
|
|
|
330
|
-
server.log.
|
|
330
|
+
server.log.on('fail', (_, error) =>
|
|
331
331
|
{
|
|
332
332
|
errorLoggerCalled = true
|
|
333
333
|
assert.equal(error.code, 'E_ROUTER_DISPATCH_FAILED', 'Should throw router error')
|
|
334
334
|
assert.equal(error.cause.code, 'E_TEST_FAILED_DISPATCHER', 'The error should have the dispatcher error as cause')
|
|
335
|
-
}
|
|
335
|
+
})
|
|
336
336
|
|
|
337
337
|
const response = await request.get(`/test/foo`)
|
|
338
338
|
|
|
@@ -354,12 +354,12 @@ suite('@superhero/http-server', () =>
|
|
|
354
354
|
|
|
355
355
|
let errorLoggerCalled = false
|
|
356
356
|
|
|
357
|
-
server.log.
|
|
357
|
+
server.log.on('fail', (_, error) =>
|
|
358
358
|
{
|
|
359
359
|
errorLoggerCalled = true
|
|
360
360
|
assert.equal(error.code, 'E_ROUTER_DISPATCH_FAILED')
|
|
361
361
|
assert.equal(error.cause.code, 'E_HTTP_SERVER_VIEW_MODEL_PROPERTY_NOT_READABLE')
|
|
362
|
-
}
|
|
362
|
+
})
|
|
363
363
|
|
|
364
364
|
const response = await request.get(`/test/foo`)
|
|
365
365
|
|
|
@@ -381,12 +381,12 @@ suite('@superhero/http-server', () =>
|
|
|
381
381
|
|
|
382
382
|
let errorLoggerCalled = false
|
|
383
383
|
|
|
384
|
-
server.log.
|
|
384
|
+
server.log.on('fail', (_, error) =>
|
|
385
385
|
{
|
|
386
386
|
errorLoggerCalled = true
|
|
387
387
|
assert.equal(error.code, 'E_ROUTER_DISPATCH_FAILED')
|
|
388
388
|
assert.equal(error.cause.code, 'E_HTTP_SERVER_VIEW_MODEL_PROPERTY_NOT_WRITABLE')
|
|
389
|
-
}
|
|
389
|
+
})
|
|
390
390
|
|
|
391
391
|
const response = await request.get(`/test/foo`)
|
|
392
392
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superhero/http-server",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "HTTP(S) server component supporting both HTTP 1.1 and HTTP 2.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"http server",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@superhero/router": "^4.1.1",
|
|
26
|
-
"@superhero/deep": "^4.1.0"
|
|
26
|
+
"@superhero/deep": "^4.1.0",
|
|
27
|
+
"@superhero/log": "^4.0.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@superhero/config": "^4.1.2",
|