@ayankhandelwal07/local-loop 1.1.7 → 1.1.9

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.
Files changed (2) hide show
  1. package/dist/index.js +30 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10,6 +10,9 @@ const axios_1 = __importDefault(require("axios"));
10
10
  const chalk_1 = __importDefault(require("chalk"));
11
11
  const PRODUCTION_SERVER = 'https://localloop-server.onrender.com';
12
12
  const PRODUCTION_DASHBOARD_URL = 'https://local-loop-gamma.vercel.app';
13
+ // const PRODUCTION_SERVER = 'http://localhost:3000';
14
+ // const PRODUCTION_DASHBOARD_URL = 'http://localhost:5173'
15
+ let heartbeatInterval;
13
16
  const program = new commander_1.Command();
14
17
  program
15
18
  .version('1.0.1')
@@ -36,6 +39,12 @@ socket.on('connect', () => {
36
39
  });
37
40
  socket.on('registered', (data) => {
38
41
  console.log(chalk_1.default.green(`\nšŸŽ‰ Tunnel Live at: ${chalk_1.default.bold(data.url)}`));
42
+ const fullId = data.url.split('/hook/')[1];
43
+ if (heartbeatInterval)
44
+ clearInterval(heartbeatInterval);
45
+ heartbeatInterval = setInterval(() => {
46
+ socket.emit('heartbeat', { subdomain: fullId });
47
+ }, 30000);
39
48
  const pathParts = data.url.split('/hook/')[1];
40
49
  console.log(chalk_1.default.green(`šŸ“Š Dashboard: ${PRODUCTION_DASHBOARD_URL}/dashboard/${pathParts}`));
41
50
  console.log(chalk_1.default.yellow(`Waiting for requests...\n`));
@@ -49,21 +58,34 @@ socket.on("incoming-request", async (payload, callback) => {
49
58
  const { method, path, body, headers } = payload;
50
59
  console.log(chalk_1.default.blue(`šŸ“Ø ${method} ${path}`));
51
60
  try {
52
- delete headers["host"];
53
- headers["host"] = `localhost:${options.port}`;
54
- delete headers["content-length"];
55
- delete headers["accept-encoding"];
61
+ const cleanHeaders = { ...headers };
62
+ Object.keys(cleanHeaders).forEach(key => {
63
+ const lowerKey = key.toLowerCase();
64
+ if (lowerKey === 'host' ||
65
+ lowerKey === 'content-length' ||
66
+ lowerKey === 'accept-encoding' ||
67
+ lowerKey === 'origin' ||
68
+ lowerKey === 'referer') {
69
+ delete cleanHeaders[key];
70
+ }
71
+ });
72
+ cleanHeaders["host"] = `localhost:${options.port}`;
56
73
  const response = await (0, axios_1.default)({
57
74
  method: method,
58
75
  url: `${LOCAL_TARGET}/${path}`,
59
- headers: headers,
76
+ headers: cleanHeaders,
60
77
  data: body,
61
78
  validateStatus: () => true
62
79
  });
63
80
  console.log(chalk_1.default.green(` ↳ Forwarded Successfully (${response.status})`));
81
+ const responseHeaders = { ...response.headers };
82
+ delete responseHeaders["content-length"];
83
+ delete responseHeaders["transfer-encoding"];
84
+ delete responseHeaders["content-encoding"];
85
+ delete responseHeaders["connection"];
64
86
  const responseToProxy = {
65
87
  status: response.status,
66
- headers: response.headers,
88
+ headers: responseHeaders,
67
89
  data: response.data
68
90
  };
69
91
  callback(responseToProxy);
@@ -87,5 +109,7 @@ socket.on("incoming-request", async (payload, callback) => {
87
109
  }
88
110
  });
89
111
  socket.on('disconnect', () => {
112
+ if (heartbeatInterval)
113
+ clearInterval(heartbeatInterval);
90
114
  console.log(chalk_1.default.red('\nšŸ”Œ Disconnected from Proxy. Retrying...'));
91
115
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ayankhandelwal07/local-loop",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "bin": {
5
5
  "super-loop": "dist/index.js"
6
6
  },