@ayankhandelwal07/local-loop 1.2.0 → 1.3.1

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