@ayankhandelwal07/local-loop 1.2.0 → 1.3.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.
Files changed (2) hide show
  1. package/dist/index.js +68 -31
  2. package/package.json +4 -1
package/dist/index.js CHANGED
@@ -8,16 +8,18 @@ const commander_1 = require("commander");
8
8
  const socket_io_client_1 = require("socket.io-client");
9
9
  const axios_1 = __importDefault(require("axios"));
10
10
  const chalk_1 = __importDefault(require("chalk"));
11
+ const boxen_1 = __importDefault(require("boxen"));
12
+ const ora_1 = __importDefault(require("ora"));
13
+ const clipboardy_1 = __importDefault(require("clipboardy"));
11
14
  // const PRODUCTION_SERVER = 'https://localloop-server.onrender.com';
12
15
  // const PRODUCTION_DASHBOARD_URL = 'https://local-loop-gamma.vercel.app'
13
16
  const PRODUCTION_SERVER = 'http://localhost:3000';
14
17
  const PRODUCTION_DASHBOARD_URL = 'http://localhost:5173';
15
- let heartbeatInterval;
16
18
  const program = new commander_1.Command();
17
19
  program
18
20
  .version('1.0.1')
19
21
  .requiredOption('-p, --port <number>', 'Local port to forward', '3000')
20
- .option('-s, --subdomain <string>', 'Desired subdomain', 'random-dev')
22
+ .option('-s, --subdomain <string>', 'Desired subdomain')
21
23
  .option('-h, --host <string>', 'Proxy Server URL', process.env.PROXY_HOST || PRODUCTION_SERVER)
22
24
  .option('-k, --key <string>', 'Your Api Key')
23
25
  .option('-a, --auth <string>', 'Basic Auth (user:password)')
@@ -25,51 +27,75 @@ program
25
27
  const options = program.opts();
26
28
  const LOCAL_TARGET = `http://localhost:${options.port}`;
27
29
  const PROXY_URL = options.host;
28
- console.log(chalk_1.default.cyan(`\nšŸš€ LocalLoop Starting...`));
29
- console.log(chalk_1.default.gray(`Target: ${LOCAL_TARGET}`));
30
- console.log(chalk_1.default.gray(`Proxy: ${PROXY_URL}`));
30
+ const spinner = (0, ora_1.default)({
31
+ text: 'Connecting to LocalLoop Cloud...',
32
+ color: 'cyan'
33
+ }).start();
31
34
  const socket = (0, socket_io_client_1.io)(PROXY_URL, {
32
35
  auth: {
33
36
  apiKey: options.key
34
37
  }
35
38
  });
39
+ let heartbeatInterval;
36
40
  socket.on('connect', () => {
37
- console.log(chalk_1.default.green(`\nāœ… Connected to Proxy!`));
38
- console.log(`Registering subdomain: ${chalk_1.default.bold(options.subdomain)}...`);
41
+ spinner.text = 'Authenticating...';
39
42
  socket.emit('register', {
40
43
  subdomain: options.subdomain,
41
44
  auth: options.auth
42
45
  });
43
46
  });
44
47
  socket.on('registered', (data) => {
45
- console.log(chalk_1.default.green(`\nšŸŽ‰ Tunnel Live at: ${chalk_1.default.bold(data.url)}`));
46
- const fullId = data.url.split('/hook/')[1];
48
+ spinner.succeed('Tunnel Established!');
49
+ const fullId = data.url.split('/hook/')[1].replace(/\/$/, "");
50
+ const dashboardUrl = `${PRODUCTION_DASHBOARD_URL}/dashboard/${fullId}`;
51
+ try {
52
+ clipboardy_1.default.writeSync(data.url);
53
+ }
54
+ catch (e) { }
55
+ const infoBox = `
56
+ ${chalk_1.default.bold.cyan('LocalLoop v1.0')} šŸš€
57
+
58
+ ${chalk_1.default.green('āœ”')} ${chalk_1.default.bold('Tunnel Active')}
59
+ ${chalk_1.default.gray('---------------------------------------------------')}
60
+
61
+ šŸŒ ${chalk_1.default.bold('Public URL:')} ${chalk_1.default.white(data.url)}
62
+ šŸ’» ${chalk_1.default.bold('Local URL:')} ${chalk_1.default.white(LOCAL_TARGET)}
63
+ šŸ“Š ${chalk_1.default.bold('Dashboard:')} ${chalk_1.default.blue(dashboardUrl)}
64
+
65
+ ${options.auth ? `šŸ”’ ${chalk_1.default.bold('Auth:')} ${chalk_1.default.yellow('Enabled')}` : `šŸ”“ ${chalk_1.default.bold('Auth:')} ${chalk_1.default.gray('None')}`}
66
+
67
+ ${chalk_1.default.gray('---------------------------------------------------')}
68
+ ${chalk_1.default.italic.gray('URL copied to clipboard!')}
69
+ `;
70
+ console.log((0, boxen_1.default)(infoBox, {
71
+ padding: 1,
72
+ margin: 1,
73
+ borderStyle: 'round',
74
+ borderColor: 'cyan',
75
+ backgroundColor: '#111'
76
+ }));
47
77
  if (heartbeatInterval)
48
78
  clearInterval(heartbeatInterval);
49
79
  heartbeatInterval = setInterval(() => {
50
80
  socket.emit('heartbeat', { subdomain: fullId });
51
81
  }, 30000);
52
- const pathParts = data.url.split('/hook/')[1];
53
- console.log(chalk_1.default.green(`šŸ“Š Dashboard: ${PRODUCTION_DASHBOARD_URL}/dashboard/${pathParts}`));
54
- console.log(chalk_1.default.yellow(`Waiting for requests...\n`));
82
+ console.log(chalk_1.default.gray(`\nWaiting for incoming requests...`));
55
83
  });
56
84
  socket.on('error', (err) => {
85
+ spinner.fail(chalk_1.default.red('Connection Failed'));
57
86
  const message = err.message || err;
58
87
  console.error(chalk_1.default.red(`āŒ Error: ${message}`));
59
88
  process.exit(1);
60
89
  });
61
90
  socket.on("incoming-request", async (payload, callback) => {
62
91
  const { method, path, body, headers } = payload;
63
- console.log(chalk_1.default.blue(`šŸ“Ø ${method} ${path}`));
92
+ const methodColor = method === 'GET' ? chalk_1.default.blue : method === 'POST' ? chalk_1.default.green : chalk_1.default.yellow;
93
+ process.stdout.write(`${methodColor(method)} ${path} `);
64
94
  try {
65
95
  const cleanHeaders = { ...headers };
66
96
  Object.keys(cleanHeaders).forEach(key => {
67
97
  const lowerKey = key.toLowerCase();
68
- if (lowerKey === 'host' ||
69
- lowerKey === 'content-length' ||
70
- lowerKey === 'accept-encoding' ||
71
- lowerKey === 'origin' ||
72
- lowerKey === 'referer') {
98
+ if (['host', 'content-length', 'accept-encoding', 'origin', 'referer'].includes(lowerKey)) {
73
99
  delete cleanHeaders[key];
74
100
  }
75
101
  });
@@ -79,41 +105,52 @@ socket.on("incoming-request", async (payload, callback) => {
79
105
  url: `${LOCAL_TARGET}/${path}`,
80
106
  headers: cleanHeaders,
81
107
  data: body,
82
- validateStatus: () => true
108
+ validateStatus: () => true,
109
+ responseType: 'arraybuffer'
83
110
  });
84
- console.log(chalk_1.default.green(` ↳ Forwarded Successfully (${response.status})`));
111
+ const statusColor = response.status < 300 ? chalk_1.default.green : response.status < 400 ? chalk_1.default.yellow : chalk_1.default.red;
112
+ console.log(`→ ${statusColor(response.status)}`);
85
113
  const responseHeaders = { ...response.headers };
86
114
  delete responseHeaders["content-length"];
87
115
  delete responseHeaders["transfer-encoding"];
88
116
  delete responseHeaders["content-encoding"];
89
117
  delete responseHeaders["connection"];
118
+ const contentType = (responseHeaders['content-type'] || '').toLowerCase();
119
+ const isBinary = contentType.includes('image') ||
120
+ contentType.includes('pdf') ||
121
+ contentType.includes('zip') ||
122
+ contentType.includes('octet-stream') ||
123
+ contentType.includes('font') ||
124
+ contentType.includes('video') ||
125
+ contentType.includes('audio');
126
+ const responseData = isBinary
127
+ ? Buffer.from(response.data).toString('base64')
128
+ : Buffer.from(response.data).toString('utf8');
90
129
  const responseToProxy = {
91
130
  status: response.status,
92
131
  headers: responseHeaders,
93
- data: response.data
132
+ data: responseData,
133
+ isBinary
94
134
  };
95
135
  callback(responseToProxy);
96
136
  }
97
137
  catch (error) {
138
+ console.log(chalk_1.default.red(`→ FAILED`));
98
139
  if (error instanceof Error) {
99
- console.error(chalk_1.default.red(` ↳ Failed to connect to local app: ${error.message}`));
140
+ console.error(chalk_1.default.dim(` ${error.message}`));
100
141
  }
101
142
  else {
102
- console.error(chalk_1.default.red(` ↳ Failed to connect to local app: ${error}`));
143
+ console.error(chalk_1.default.dim(` ${String(error)}`));
103
144
  }
104
- const errorResponse = {
145
+ callback({
105
146
  status: 502,
106
147
  headers: {},
107
- data: {
108
- error: "LocalLoop Error",
109
- details: error instanceof Error ? error.message : String(error)
110
- }
111
- };
112
- callback(errorResponse);
148
+ data: JSON.stringify({ error: "LocalLoop Error", details: String(error) })
149
+ });
113
150
  }
114
151
  });
115
152
  socket.on('disconnect', () => {
116
153
  if (heartbeatInterval)
117
154
  clearInterval(heartbeatInterval);
118
- console.log(chalk_1.default.red('\nšŸ”Œ Disconnected from Proxy. Retrying...'));
155
+ console.log(chalk_1.default.yellow('\nāš ļø Disconnected from Proxy. Retrying...'));
119
156
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ayankhandelwal07/local-loop",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "bin": {
5
5
  "super-loop": "dist/index.js"
6
6
  },
@@ -25,9 +25,12 @@
25
25
  "type": "commonjs",
26
26
  "dependencies": {
27
27
  "axios": "^1.13.2",
28
+ "boxen": "^5.1.2",
28
29
  "chalk": "^4.1.2",
30
+ "clipboardy": "^2.3.0",
29
31
  "commander": "^14.0.2",
30
32
  "dotenv": "^17.2.3",
33
+ "ora": "^5.4.1",
31
34
  "socket.io-client": "^4.8.3"
32
35
  },
33
36
  "devDependencies": {