@skrillex1224/playwright-toolkit 2.1.199 → 2.1.201
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/dist/index.cjs +2 -155
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +2 -155
- package/dist/index.js.map +2 -2
- package/dist/internals/proxy-meter.js +0 -78
- package/package.json +1 -1
|
@@ -6,7 +6,6 @@ import { URL } from 'url';
|
|
|
6
6
|
const HOST = '127.0.0.1';
|
|
7
7
|
const PORT = Number(process.env.PROXY_METER_PORT || 8899);
|
|
8
8
|
const LOG_PATH = String(process.env.PROXY_METER_LOG || '/tmp/proxy-meter.json');
|
|
9
|
-
const STATE_PATH = String(process.env.PROXY_METER_STATE || '').trim();
|
|
10
9
|
const FLUSH_INTERVAL_MS = Number(process.env.PROXY_METER_FLUSH_MS || 5000);
|
|
11
10
|
const UPSTREAM_URL = String(process.env.PROXY_METER_UPSTREAM || '').trim();
|
|
12
11
|
const RUN_ID = String(process.env.PROXY_METER_RUN_ID || process.env.APIFY_ACTOR_RUN_ID || '').trim();
|
|
@@ -33,31 +32,6 @@ const state = {
|
|
|
33
32
|
: null,
|
|
34
33
|
};
|
|
35
34
|
|
|
36
|
-
let lifecycleState = {
|
|
37
|
-
pid: process.pid,
|
|
38
|
-
status: 'starting',
|
|
39
|
-
host: HOST,
|
|
40
|
-
port: PORT,
|
|
41
|
-
startedAt: state.startedAt,
|
|
42
|
-
readyAt: '',
|
|
43
|
-
exitedAt: '',
|
|
44
|
-
exitCode: null,
|
|
45
|
-
error: '',
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const writeLifecycleState = (patch = {}) => {
|
|
49
|
-
if (!STATE_PATH) return;
|
|
50
|
-
lifecycleState = {
|
|
51
|
-
...lifecycleState,
|
|
52
|
-
...patch,
|
|
53
|
-
};
|
|
54
|
-
try {
|
|
55
|
-
fs.writeFileSync(STATE_PATH, JSON.stringify(lifecycleState, null, 2));
|
|
56
|
-
} catch {}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
writeLifecycleState();
|
|
60
|
-
|
|
61
35
|
const getHostBucket = (host) => {
|
|
62
36
|
if (!host) return null;
|
|
63
37
|
if (!state.hosts[host]) {
|
|
@@ -318,33 +292,6 @@ const parseUpstream = () => {
|
|
|
318
292
|
};
|
|
319
293
|
};
|
|
320
294
|
|
|
321
|
-
let fatalSignal = '';
|
|
322
|
-
const markFatal = (error) => {
|
|
323
|
-
fatalSignal = safeError(error);
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
process.on('uncaughtException', (error) => {
|
|
327
|
-
markFatal(error);
|
|
328
|
-
writeLifecycleState({
|
|
329
|
-
status: 'exited',
|
|
330
|
-
exitedAt: new Date().toISOString(),
|
|
331
|
-
exitCode: 1,
|
|
332
|
-
error: fatalSignal || 'uncaught_exception',
|
|
333
|
-
});
|
|
334
|
-
process.exit(1);
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
process.on('unhandledRejection', (error) => {
|
|
338
|
-
markFatal(error);
|
|
339
|
-
writeLifecycleState({
|
|
340
|
-
status: 'exited',
|
|
341
|
-
exitedAt: new Date().toISOString(),
|
|
342
|
-
exitCode: 1,
|
|
343
|
-
error: fatalSignal || 'unhandled_rejection',
|
|
344
|
-
});
|
|
345
|
-
process.exit(1);
|
|
346
|
-
});
|
|
347
|
-
|
|
348
295
|
const upstream = parseUpstream();
|
|
349
296
|
|
|
350
297
|
const resolveTarget = (req) => {
|
|
@@ -586,23 +533,7 @@ const forwardConnect = (req, clientSocket, head) => {
|
|
|
586
533
|
|
|
587
534
|
const server = http.createServer(forwardHttp);
|
|
588
535
|
server.on('connect', forwardConnect);
|
|
589
|
-
server.on('error', (error) => {
|
|
590
|
-
markFatal(error);
|
|
591
|
-
writeLifecycleState({
|
|
592
|
-
status: 'exited',
|
|
593
|
-
exitedAt: new Date().toISOString(),
|
|
594
|
-
exitCode: 1,
|
|
595
|
-
error: fatalSignal || 'server_error',
|
|
596
|
-
});
|
|
597
|
-
flushSnapshot();
|
|
598
|
-
process.exit(1);
|
|
599
|
-
});
|
|
600
536
|
server.listen(PORT, HOST, () => {
|
|
601
|
-
writeLifecycleState({
|
|
602
|
-
status: 'ready',
|
|
603
|
-
readyAt: new Date().toISOString(),
|
|
604
|
-
error: '',
|
|
605
|
-
});
|
|
606
537
|
console.log(`[proxy-meter] listening ${HOST}:${PORT} log=${LOG_PATH}`);
|
|
607
538
|
});
|
|
608
539
|
|
|
@@ -616,12 +547,3 @@ const shutdown = () => {
|
|
|
616
547
|
|
|
617
548
|
process.on('SIGINT', shutdown);
|
|
618
549
|
process.on('SIGTERM', shutdown);
|
|
619
|
-
process.on('exit', (code) => {
|
|
620
|
-
flushSnapshot();
|
|
621
|
-
writeLifecycleState({
|
|
622
|
-
status: 'exited',
|
|
623
|
-
exitedAt: new Date().toISOString(),
|
|
624
|
-
exitCode: Number.isFinite(code) ? code : null,
|
|
625
|
-
error: fatalSignal,
|
|
626
|
-
});
|
|
627
|
-
});
|