@ayankhandelwal07/local-loop 1.1.6

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 +89 -0
  2. package/package.json +39 -0
package/dist/index.js ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const commander_1 = require("commander");
8
+ const socket_io_client_1 = require("socket.io-client");
9
+ const axios_1 = __importDefault(require("axios"));
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 program = new commander_1.Command();
14
+ program
15
+ .version('1.0.1')
16
+ .requiredOption('-p, --port <number>', 'Local port to forward', '3000')
17
+ .option('-s, --subdomain <string>', 'Desired subdomain', 'random-dev')
18
+ .option('-h, --host <string>', 'Proxy Server URL', process.env.PROXY_HOST || PRODUCTION_SERVER)
19
+ .option('-k, --key <string>', 'Your Api Key')
20
+ .parse(process.argv);
21
+ const options = program.opts();
22
+ const LOCAL_TARGET = `http://localhost:${options.port}`;
23
+ const PROXY_URL = options.host;
24
+ console.log(chalk_1.default.cyan(`\nšŸš€ LocalLoop Starting...`));
25
+ console.log(chalk_1.default.gray(`Target: ${LOCAL_TARGET}`));
26
+ console.log(chalk_1.default.gray(`Proxy: ${PROXY_URL}`));
27
+ const socket = (0, socket_io_client_1.io)(PROXY_URL, {
28
+ auth: {
29
+ apiKey: options.key
30
+ }
31
+ });
32
+ socket.on('connect', () => {
33
+ console.log(chalk_1.default.green(`\nāœ… Connected to Proxy!`));
34
+ console.log(`Registering subdomain: ${chalk_1.default.bold(options.subdomain)}...`);
35
+ socket.emit('register', options.subdomain);
36
+ });
37
+ socket.on('registered', (data) => {
38
+ console.log(chalk_1.default.green(`\nšŸŽ‰ Tunnel Live at: ${chalk_1.default.bold(data.url)}`));
39
+ const pathParts = data.url.split('/hook/')[1];
40
+ console.log(chalk_1.default.green(`šŸ“Š Dashboard: ${PRODUCTION_DASHBOARD_URL}/dashboard/${pathParts}`));
41
+ console.log(chalk_1.default.yellow(`Waiting for requests...\n`));
42
+ });
43
+ socket.on('error', (err) => {
44
+ const message = err.message || err;
45
+ console.error(chalk_1.default.red(`āŒ Error: ${message}`));
46
+ process.exit(1);
47
+ });
48
+ socket.on("incoming-request", async (payload, callback) => {
49
+ const { method, path, body, headers } = payload;
50
+ console.log(chalk_1.default.blue(`šŸ“Ø ${method} ${path}`));
51
+ try {
52
+ delete headers["host"];
53
+ headers["host"] = `localhost:${options.port}`;
54
+ const response = await (0, axios_1.default)({
55
+ method: method,
56
+ url: `${LOCAL_TARGET}/${path}`,
57
+ headers: headers,
58
+ data: body,
59
+ validateStatus: () => true
60
+ });
61
+ console.log(chalk_1.default.green(` ↳ Forwarded Successfully (${response.status})`));
62
+ const responseToProxy = {
63
+ status: response.status,
64
+ headers: response.headers,
65
+ data: response.data
66
+ };
67
+ callback(responseToProxy);
68
+ }
69
+ catch (error) {
70
+ if (error instanceof Error) {
71
+ console.error(chalk_1.default.red(` ↳ Failed to connect to local app: ${error.message}`));
72
+ }
73
+ else {
74
+ console.error(chalk_1.default.red(` ↳ Failed to connect to local app: ${error}`));
75
+ }
76
+ const errorResponse = {
77
+ status: 502,
78
+ headers: {},
79
+ data: {
80
+ error: "LocalLoop Error",
81
+ details: error instanceof Error ? error.message : String(error)
82
+ }
83
+ };
84
+ callback(errorResponse);
85
+ }
86
+ });
87
+ socket.on('disconnect', () => {
88
+ console.log(chalk_1.default.red('\nšŸ”Œ Disconnected from Proxy. Retrying...'));
89
+ });
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@ayankhandelwal07/local-loop",
3
+ "version": "1.1.6",
4
+ "bin": {
5
+ "super-loop": "dist/index.js"
6
+ },
7
+ "description": "A localhost tunneling tool",
8
+ "main": "dist/index.js",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "start": "node dist/index.js",
15
+ "prepublishOnly": "npm run build",
16
+ "test": "echo \"Error: no test specified\" && exit 1"
17
+ },
18
+ "keywords": [
19
+ "tunnel",
20
+ "localhost",
21
+ "proxy"
22
+ ],
23
+ "author": "Your Name",
24
+ "license": "ISC",
25
+ "type": "commonjs",
26
+ "dependencies": {
27
+ "axios": "^1.13.2",
28
+ "chalk": "^4.1.2",
29
+ "commander": "^14.0.2",
30
+ "dotenv": "^17.2.3",
31
+ "socket.io-client": "^4.8.3"
32
+ },
33
+ "devDependencies": {
34
+ "@types/commander": "^2.12.0",
35
+ "@types/node": "^25.0.3",
36
+ "ts-node": "^10.9.2",
37
+ "typescript": "^5.9.3"
38
+ }
39
+ }