@dokebi/web 0.4.3 → 0.4.4
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/AI.md +2 -0
- package/dist/index.js +35 -1
- package/package.json +1 -1
package/AI.md
CHANGED
|
@@ -223,6 +223,8 @@ A tunnel or proxy that forwards to this app usually connects from this machine a
|
|
|
223
223
|
2. **The public host is a known host**: an @dokebi/app domain (`options.dokebi-app.domains`), and in development also `options.dokebi-template-inertia.devHosts`.
|
|
224
224
|
3. **Nothing else**: the tunnel's HTTP Host Header may stay `localhost`; no change on the tunnel side is needed.
|
|
225
225
|
|
|
226
|
+
A request Node's HTTP parser refuses gets a bare 400 (408 for a request timeout, 431 for headers too large) before any route, so the request log never shows it. web logs it as `WEB_CLIENT_ERROR` (`error` the parser's code such as `HPE_CLOSED_CONNECTION` or `HPE_INVALID_METHOD`, `reason`, `bytesParsed`, `status`, `remote`; never the request bytes): at **warn** with a `fix` when the peer is in `trustProxy` (your own proxy sent it: its configuration), once per peer, code and `logRepeatWindowMs` with `repeated`; at debug for any other peer. `HPE_CLOSED_CONNECTION` from a proxy means it sent a request on a connection the app had answered with `Connection: close`: send `Connection ""` upstream for keep-alive (as `dokebi deploy proxy --nginx` writes it).
|
|
227
|
+
|
|
226
228
|
What goes wrong without step 1: the app is chosen by `localhost` (the public host is not matched), and on a seal host the first Inertia page does not decrypt in the browser — the seal key uses the host, `requestHost()` on the server and the address bar on the browser, and they must be the same. Check: `web.requestHost(request)` must equal the host in the browser's address bar. Development HMR goes through the page's own origin, so it works through the tunnel too (@dokebi/template-inertia AI.md §5.1).
|
|
227
229
|
|
|
228
230
|
## 3. Start and request blocking
|
package/dist/index.js
CHANGED
|
@@ -413,6 +413,40 @@ class WebOwner {
|
|
|
413
413
|
http2: created.http2 === true,
|
|
414
414
|
logger,
|
|
415
415
|
});
|
|
416
|
+
// A request Node's HTTP parser refuses (a malformed line, data after `Connection: close`, a
|
|
417
|
+
// header block too large, a request timeout) gets Fastify's bare 400/408/431 before any route,
|
|
418
|
+
// and Fastify records it only at trace. From a peer in trustProxy (the deployment's own
|
|
419
|
+
// proxy) that is a configuration fault to fix: a warning, once per window, peer and code.
|
|
420
|
+
// From any other peer it is debug: an internet client may send anything. The request bytes
|
|
421
|
+
// (`rawPacket`) can hold tokens and are never logged. Prepended: Fastify's own listener
|
|
422
|
+
// answers and destroys the socket, after which its peer address is gone.
|
|
423
|
+
const clientErrors = new Repeats({ intervalMs: options.logRepeatWindowMs });
|
|
424
|
+
this.server.server.prependListener('clientError', (error, socket) => {
|
|
425
|
+
if (error.code === 'ECONNRESET' || socket.destroyed)
|
|
426
|
+
return;
|
|
427
|
+
const peer = plainAddress(socket.remoteAddress ?? '?');
|
|
428
|
+
const proxy = options.trustProxy.includes(peer);
|
|
429
|
+
if (!proxy && !logger.isEnabled('debug'))
|
|
430
|
+
return;
|
|
431
|
+
const code = typeof error.code === 'string' ? error.code : 'UNKNOWN';
|
|
432
|
+
const repeated = proxy ? clientErrors.take(`${peer} ${code}`) : 0;
|
|
433
|
+
if (repeated === undefined)
|
|
434
|
+
return;
|
|
435
|
+
logger.log(proxy ? 'warn' : 'debug', 'A request was refused before any route', {
|
|
436
|
+
code: 'WEB_CLIENT_ERROR',
|
|
437
|
+
error: code,
|
|
438
|
+
...(typeof error.reason === 'string' ? { reason: error.reason.slice(0, 200) } : {}),
|
|
439
|
+
...(typeof error.bytesParsed === 'number' ? { bytesParsed: error.bytesParsed } : {}),
|
|
440
|
+
status: code === 'ERR_HTTP_REQUEST_TIMEOUT' ? 408 : code === 'HPE_HEADER_OVERFLOW' ? 431 : 400,
|
|
441
|
+
remote: peer,
|
|
442
|
+
...(proxy
|
|
443
|
+
? {
|
|
444
|
+
fix: 'The peer is your proxy (trustProxy): check what it sends upstream. HPE_CLOSED_CONNECTION: it reused a connection the app answered with close (send Connection "" upstream with keepalive, as deploy proxy --nginx writes it).',
|
|
445
|
+
}
|
|
446
|
+
: {}),
|
|
447
|
+
...(repeated ? { repeated } : {}),
|
|
448
|
+
});
|
|
449
|
+
});
|
|
416
450
|
const lazySchemas = restoreDefaultCompilers(this.server, created.schemaController, schemaController);
|
|
417
451
|
const owner = this;
|
|
418
452
|
logger.log('debug', 'Web server configured', {
|
|
@@ -2424,7 +2458,7 @@ class WebRuntime {
|
|
|
2424
2458
|
}
|
|
2425
2459
|
export const createPlugin = definePlugin({
|
|
2426
2460
|
name: 'dokebi-web',
|
|
2427
|
-
version: '0.4.
|
|
2461
|
+
version: '0.4.4',
|
|
2428
2462
|
core: '^0.4.2',
|
|
2429
2463
|
options: declaration,
|
|
2430
2464
|
entry: (input) => new WebEntryInput(input),
|