querysub 0.83.0 → 0.85.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "querysub",
3
- "version": "0.83.0",
3
+ "version": "0.85.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
@@ -17,9 +17,8 @@ export async function hackDevtoolsWebsocketForward(config: {
17
17
  externalPort: number;
18
18
  cancel: () => void;
19
19
  }> {
20
- const forwardCode = (() => {
20
+ const forwardCode = ((configInner: typeof config) => {
21
21
  const net = require("net");
22
- const config = JSON.parse(process.argv[2]);
23
22
  const server = net.createServer();
24
23
 
25
24
  // Start listening on a random available port, binding to all interfaces (0.0.0.0)
@@ -28,7 +27,7 @@ export async function hackDevtoolsWebsocketForward(config: {
28
27
  server.on("connection", (socket: net.Socket) => {
29
28
  const clientIP = socket.remoteAddress;
30
29
 
31
- if (clientIP !== config.externalIP) {
30
+ if (clientIP !== configInner.externalIP) {
32
31
  console.error(`Rejected connection attempt from unauthorized IP: ${clientIP}`);
33
32
  socket.destroy();
34
33
  return;
@@ -39,12 +38,12 @@ export async function hackDevtoolsWebsocketForward(config: {
39
38
  throw new Error("Failed to get server address");
40
39
  }
41
40
 
42
- console.log(`Forwarding connection from ${config.externalIP}:${address.port} to 127.0.0.1:${config.internalPort}`);
41
+ console.log(`Forwarding connection from ${configInner.externalIP}:${address.port} to 127.0.0.1:${configInner.internalPort}`);
43
42
 
44
43
  // Forward the connection to the internal port
45
44
  const internalConnection = net.createConnection({
46
45
  host: "127.0.0.1",
47
- port: config.internalPort,
46
+ port: configInner.internalPort,
48
47
  });
49
48
  internalConnection.on("data", (data: Buffer) => {
50
49
  socket.write(data);
@@ -55,7 +54,7 @@ export async function hackDevtoolsWebsocketForward(config: {
55
54
  if (first) {
56
55
  first = false;
57
56
  let lines = data.toString().split("\r\n");
58
- lines[1] = `Host: 127.0.0.1:${config.internalPort}`;
57
+ lines[1] = `Host: 127.0.0.1:${configInner.internalPort}`;
59
58
  data = Buffer.from(lines.join("\r\n"));
60
59
  }
61
60
  internalConnection.write(data);
@@ -88,12 +87,12 @@ export async function hackDevtoolsWebsocketForward(config: {
88
87
 
89
88
  console.log(`EXTERNAL_PORT:${address.port}`);
90
89
  });
91
- }).toString();
90
+ });
92
91
 
92
+ console.log(`Forwarding to 127.0.0.1:${config.internalPort} for ${config.externalIP}`);
93
93
  const child = child_process.spawn("node", [
94
94
  "-e",
95
- `(${forwardCode})()`,
96
- JSON.stringify(config)
95
+ `(${forwardCode.toString()})(${JSON.stringify(config)})`,
97
96
  ]);
98
97
 
99
98
  let externalPort: number | undefined;
@@ -127,6 +126,8 @@ export async function hackDevtoolsWebsocketForward(config: {
127
126
  // Wait for the port to be available
128
127
  externalPort = await portPromise;
129
128
 
129
+ console.log(`Forwarded external port ${externalPort} => ${config.internalPort} for ${config.externalIP}`);
130
+
130
131
  return {
131
132
  externalPort,
132
133
  cancel: () => {