test-proxy-recorder 0.3.3 → 0.3.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/dist/index.cjs +5 -9
- package/dist/index.d.cts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.mjs +5 -9
- package/dist/proxy.js +24 -28
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -131,8 +131,7 @@ function sendJsonResponse(res, statusCode, data) {
|
|
|
131
131
|
|
|
132
132
|
// src/ProxyServer.ts
|
|
133
133
|
var ProxyServer = class {
|
|
134
|
-
|
|
135
|
-
currentTargetIndex;
|
|
134
|
+
target;
|
|
136
135
|
mode;
|
|
137
136
|
recordingId;
|
|
138
137
|
replayId;
|
|
@@ -150,9 +149,8 @@ var ProxyServer = class {
|
|
|
150
149
|
// Stack of promises that resolve to completed recordings
|
|
151
150
|
flushPromise;
|
|
152
151
|
// Promise for in-progress flush operation
|
|
153
|
-
constructor(
|
|
154
|
-
this.
|
|
155
|
-
this.currentTargetIndex = 0;
|
|
152
|
+
constructor(target, recordingsDir) {
|
|
153
|
+
this.target = target;
|
|
156
154
|
this.mode = Modes.transparent;
|
|
157
155
|
this.recordingId = null;
|
|
158
156
|
this.recordingIdCounter = 0;
|
|
@@ -225,9 +223,7 @@ var ProxyServer = class {
|
|
|
225
223
|
Object.assign(proxyRes.headers, corsHeaders);
|
|
226
224
|
}
|
|
227
225
|
getTarget() {
|
|
228
|
-
|
|
229
|
-
this.currentTargetIndex = (this.currentTargetIndex + 1) % this.targets.length;
|
|
230
|
-
return target;
|
|
226
|
+
return this.target;
|
|
231
227
|
}
|
|
232
228
|
/**
|
|
233
229
|
* Extract recording ID from custom HTTP header
|
|
@@ -959,7 +955,7 @@ var ProxyServer = class {
|
|
|
959
955
|
logServerStartup(port) {
|
|
960
956
|
console.log(`Proxy server running on http://localhost:${port}`);
|
|
961
957
|
console.log(`Mode: ${this.mode}`);
|
|
962
|
-
console.log(`
|
|
958
|
+
console.log(`Target: ${this.target}`);
|
|
963
959
|
console.log(
|
|
964
960
|
`Control endpoint: http://localhost:${port}${CONTROL_ENDPOINT}`
|
|
965
961
|
);
|
package/dist/index.d.cts
CHANGED
|
@@ -4,8 +4,7 @@ export { C as ControlRequest, M as Mode, P as PlaywrightTestInfo, R as Recording
|
|
|
4
4
|
import '@playwright/test';
|
|
5
5
|
|
|
6
6
|
declare class ProxyServer {
|
|
7
|
-
private
|
|
8
|
-
private currentTargetIndex;
|
|
7
|
+
private target;
|
|
9
8
|
private mode;
|
|
10
9
|
private recordingId;
|
|
11
10
|
private replayId;
|
|
@@ -18,7 +17,7 @@ declare class ProxyServer {
|
|
|
18
17
|
private replaySessions;
|
|
19
18
|
private recordingPromises;
|
|
20
19
|
private flushPromise;
|
|
21
|
-
constructor(
|
|
20
|
+
constructor(target: string, recordingsDir: string);
|
|
22
21
|
init(): Promise<void>;
|
|
23
22
|
listen(port: number): http.Server;
|
|
24
23
|
private setupProxyEventHandlers;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,7 @@ export { C as ControlRequest, M as Mode, P as PlaywrightTestInfo, R as Recording
|
|
|
4
4
|
import '@playwright/test';
|
|
5
5
|
|
|
6
6
|
declare class ProxyServer {
|
|
7
|
-
private
|
|
8
|
-
private currentTargetIndex;
|
|
7
|
+
private target;
|
|
9
8
|
private mode;
|
|
10
9
|
private recordingId;
|
|
11
10
|
private replayId;
|
|
@@ -18,7 +17,7 @@ declare class ProxyServer {
|
|
|
18
17
|
private replaySessions;
|
|
19
18
|
private recordingPromises;
|
|
20
19
|
private flushPromise;
|
|
21
|
-
constructor(
|
|
20
|
+
constructor(target: string, recordingsDir: string);
|
|
22
21
|
init(): Promise<void>;
|
|
23
22
|
listen(port: number): http.Server;
|
|
24
23
|
private setupProxyEventHandlers;
|
package/dist/index.mjs
CHANGED
|
@@ -119,8 +119,7 @@ function sendJsonResponse(res, statusCode, data) {
|
|
|
119
119
|
|
|
120
120
|
// src/ProxyServer.ts
|
|
121
121
|
var ProxyServer = class {
|
|
122
|
-
|
|
123
|
-
currentTargetIndex;
|
|
122
|
+
target;
|
|
124
123
|
mode;
|
|
125
124
|
recordingId;
|
|
126
125
|
replayId;
|
|
@@ -138,9 +137,8 @@ var ProxyServer = class {
|
|
|
138
137
|
// Stack of promises that resolve to completed recordings
|
|
139
138
|
flushPromise;
|
|
140
139
|
// Promise for in-progress flush operation
|
|
141
|
-
constructor(
|
|
142
|
-
this.
|
|
143
|
-
this.currentTargetIndex = 0;
|
|
140
|
+
constructor(target, recordingsDir) {
|
|
141
|
+
this.target = target;
|
|
144
142
|
this.mode = Modes.transparent;
|
|
145
143
|
this.recordingId = null;
|
|
146
144
|
this.recordingIdCounter = 0;
|
|
@@ -213,9 +211,7 @@ var ProxyServer = class {
|
|
|
213
211
|
Object.assign(proxyRes.headers, corsHeaders);
|
|
214
212
|
}
|
|
215
213
|
getTarget() {
|
|
216
|
-
|
|
217
|
-
this.currentTargetIndex = (this.currentTargetIndex + 1) % this.targets.length;
|
|
218
|
-
return target;
|
|
214
|
+
return this.target;
|
|
219
215
|
}
|
|
220
216
|
/**
|
|
221
217
|
* Extract recording ID from custom HTTP header
|
|
@@ -947,7 +943,7 @@ var ProxyServer = class {
|
|
|
947
943
|
logServerStartup(port) {
|
|
948
944
|
console.log(`Proxy server running on http://localhost:${port}`);
|
|
949
945
|
console.log(`Mode: ${this.mode}`);
|
|
950
|
-
console.log(`
|
|
946
|
+
console.log(`Target: ${this.target}`);
|
|
951
947
|
console.log(
|
|
952
948
|
`Control endpoint: http://localhost:${port}${CONTROL_ENDPOINT}`
|
|
953
949
|
);
|
package/dist/proxy.js
CHANGED
|
@@ -16,8 +16,8 @@ function parseCliArgs() {
|
|
|
16
16
|
program.name("dev-proxy").description(
|
|
17
17
|
"Development proxy server with recording and replay capabilities"
|
|
18
18
|
).argument(
|
|
19
|
-
"<
|
|
20
|
-
"Target API service
|
|
19
|
+
"<target>",
|
|
20
|
+
"Target API service URL (e.g., http://localhost:3000)"
|
|
21
21
|
).option(
|
|
22
22
|
"-p, --port <number>",
|
|
23
23
|
"Port number for the proxy server",
|
|
@@ -29,18 +29,18 @@ function parseCliArgs() {
|
|
|
29
29
|
).action(() => {
|
|
30
30
|
});
|
|
31
31
|
program.parse();
|
|
32
|
-
const
|
|
32
|
+
const target2 = program.args[0];
|
|
33
33
|
const options = program.opts();
|
|
34
34
|
const port2 = Number.parseInt(options.port, 10);
|
|
35
35
|
if (Number.isNaN(port2) || port2 < 1025 || port2 > 65535) {
|
|
36
36
|
console.error("Error: Invalid port number. Must be between 1 and 65535");
|
|
37
37
|
process.exit(1);
|
|
38
38
|
}
|
|
39
|
-
if (
|
|
39
|
+
if (!target2) {
|
|
40
40
|
program.help();
|
|
41
41
|
}
|
|
42
42
|
const recordingsDir2 = path.resolve(process.cwd(), options.dir);
|
|
43
|
-
return {
|
|
43
|
+
return { target: target2, port: port2, recordingsDir: recordingsDir2 };
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// src/constants.ts
|
|
@@ -155,8 +155,7 @@ function sendJsonResponse(res, statusCode, data) {
|
|
|
155
155
|
|
|
156
156
|
// src/ProxyServer.ts
|
|
157
157
|
var ProxyServer = class {
|
|
158
|
-
|
|
159
|
-
currentTargetIndex;
|
|
158
|
+
target;
|
|
160
159
|
mode;
|
|
161
160
|
recordingId;
|
|
162
161
|
replayId;
|
|
@@ -174,9 +173,8 @@ var ProxyServer = class {
|
|
|
174
173
|
// Stack of promises that resolve to completed recordings
|
|
175
174
|
flushPromise;
|
|
176
175
|
// Promise for in-progress flush operation
|
|
177
|
-
constructor(
|
|
178
|
-
this.
|
|
179
|
-
this.currentTargetIndex = 0;
|
|
176
|
+
constructor(target2, recordingsDir2) {
|
|
177
|
+
this.target = target2;
|
|
180
178
|
this.mode = Modes.transparent;
|
|
181
179
|
this.recordingId = null;
|
|
182
180
|
this.recordingIdCounter = 0;
|
|
@@ -249,9 +247,7 @@ var ProxyServer = class {
|
|
|
249
247
|
Object.assign(proxyRes.headers, corsHeaders);
|
|
250
248
|
}
|
|
251
249
|
getTarget() {
|
|
252
|
-
|
|
253
|
-
this.currentTargetIndex = (this.currentTargetIndex + 1) % this.targets.length;
|
|
254
|
-
return target;
|
|
250
|
+
return this.target;
|
|
255
251
|
}
|
|
256
252
|
/**
|
|
257
253
|
* Extract recording ID from custom HTTP header
|
|
@@ -705,16 +701,16 @@ var ProxyServer = class {
|
|
|
705
701
|
res.end();
|
|
706
702
|
}
|
|
707
703
|
async handleProxyRequest(req, res) {
|
|
708
|
-
const
|
|
709
|
-
console.log(`[${this.mode}] ${req.method} ${req.url} -> ${
|
|
704
|
+
const target2 = this.getTarget();
|
|
705
|
+
console.log(`[${this.mode}] ${req.method} ${req.url} -> ${target2}`);
|
|
710
706
|
if (this.mode === Modes.record) {
|
|
711
|
-
await this.recordAndProxyRequest(req, res,
|
|
707
|
+
await this.recordAndProxyRequest(req, res, target2);
|
|
712
708
|
} else {
|
|
713
|
-
this.proxy.web(req, res, { target });
|
|
709
|
+
this.proxy.web(req, res, { target: target2 });
|
|
714
710
|
}
|
|
715
711
|
}
|
|
716
712
|
// Note: streaming requests are buffered before proxying; streaming passthrough is not yet implemented
|
|
717
|
-
async recordAndProxyRequest(req, res,
|
|
713
|
+
async recordAndProxyRequest(req, res, target2) {
|
|
718
714
|
if (!this.currentSession) {
|
|
719
715
|
return;
|
|
720
716
|
}
|
|
@@ -742,7 +738,7 @@ var ProxyServer = class {
|
|
|
742
738
|
console.error("Error buffering request:", error);
|
|
743
739
|
}
|
|
744
740
|
const requestBody = Buffer.concat(chunks).toString("utf8");
|
|
745
|
-
const targetUrl = new URL(
|
|
741
|
+
const targetUrl = new URL(target2);
|
|
746
742
|
const isHttps = targetUrl.protocol === "https:";
|
|
747
743
|
const requestModule = isHttps ? https : http;
|
|
748
744
|
const defaultPort = isHttps ? 443 : 80;
|
|
@@ -831,15 +827,15 @@ var ProxyServer = class {
|
|
|
831
827
|
this.handleReplayWebSocket(req, socket);
|
|
832
828
|
return;
|
|
833
829
|
}
|
|
834
|
-
const
|
|
835
|
-
console.log(`[${this.mode}] WebSocket upgrade ${req.url} -> ${
|
|
830
|
+
const target2 = this.getTarget();
|
|
831
|
+
console.log(`[${this.mode}] WebSocket upgrade ${req.url} -> ${target2}`);
|
|
836
832
|
if (this.mode === Modes.record) {
|
|
837
|
-
this.handleRecordWebSocket(req, socket, head,
|
|
833
|
+
this.handleRecordWebSocket(req, socket, head, target2);
|
|
838
834
|
} else {
|
|
839
|
-
this.proxy.ws(req, socket, head, { target });
|
|
835
|
+
this.proxy.ws(req, socket, head, { target: target2 });
|
|
840
836
|
}
|
|
841
837
|
}
|
|
842
|
-
handleRecordWebSocket(req, clientSocket, head,
|
|
838
|
+
handleRecordWebSocket(req, clientSocket, head, target2) {
|
|
843
839
|
const url = req.url || "/";
|
|
844
840
|
const key = `WS_${url.replaceAll("/", "_")}`;
|
|
845
841
|
const wsRecording = {
|
|
@@ -851,7 +847,7 @@ var ProxyServer = class {
|
|
|
851
847
|
if (this.currentSession) {
|
|
852
848
|
this.currentSession.websocketRecordings.push(wsRecording);
|
|
853
849
|
}
|
|
854
|
-
const backendWsUrl = `${
|
|
850
|
+
const backendWsUrl = `${target2.replace("http", "ws")}${url}`;
|
|
855
851
|
const backendWs = new WebSocket(backendWsUrl);
|
|
856
852
|
const wss = new WebSocketServer({ noServer: true });
|
|
857
853
|
backendWs.on("open", () => {
|
|
@@ -983,7 +979,7 @@ var ProxyServer = class {
|
|
|
983
979
|
logServerStartup(port2) {
|
|
984
980
|
console.log(`Proxy server running on http://localhost:${port2}`);
|
|
985
981
|
console.log(`Mode: ${this.mode}`);
|
|
986
|
-
console.log(`
|
|
982
|
+
console.log(`Target: ${this.target}`);
|
|
987
983
|
console.log(
|
|
988
984
|
`Control endpoint: http://localhost:${port2}${CONTROL_ENDPOINT}`
|
|
989
985
|
);
|
|
@@ -991,8 +987,8 @@ var ProxyServer = class {
|
|
|
991
987
|
};
|
|
992
988
|
|
|
993
989
|
// src/proxy.ts
|
|
994
|
-
var {
|
|
995
|
-
var proxy = new ProxyServer(
|
|
990
|
+
var { target, port, recordingsDir } = parseCliArgs();
|
|
991
|
+
var proxy = new ProxyServer(target, recordingsDir);
|
|
996
992
|
await proxy.init();
|
|
997
993
|
proxy.listen(port);
|
|
998
994
|
console.log(`Recordings will be saved to: ${recordingsDir}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "test-proxy-recorder",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "HTTP proxy server for recording and replaying network requests in testing. Works seamlessly with Playwright testing framework.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|