local-loop-by-ayan 1.0.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 +77 -0
  2. package/package.json +38 -0
package/dist/index.js ADDED
@@ -0,0 +1,77 @@
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 dotenv_1 = __importDefault(require("dotenv"));
12
+ dotenv_1.default.config();
13
+ const program = new commander_1.Command();
14
+ program
15
+ .version('1.0.0')
16
+ .requiredOption('-p, --port <number>', 'Local port to forward', process.env.DEFAULT_PORT)
17
+ .option('-s, --subdomain <string>', 'Desired subdomain', 'random-dev')
18
+ .option('-h, --host <string>', 'Proxy Server URL', process.env.PROXY_HOST)
19
+ .parse(process.argv);
20
+ const options = program.opts();
21
+ const LOCAL_TARGET = `http://localhost:${options.port}`;
22
+ const PROXY_URL = options.host;
23
+ console.log(chalk_1.default.cyan(`\nšŸš€ LocalLoop Starting...`));
24
+ console.log(chalk_1.default.gray(`Target: ${LOCAL_TARGET}`));
25
+ console.log(chalk_1.default.gray(`Proxy: ${PROXY_URL}`));
26
+ const socket = (0, socket_io_client_1.io)(PROXY_URL);
27
+ socket.on('connect', () => {
28
+ console.log(chalk_1.default.green(`\nāœ… Connected to Proxy!`));
29
+ console.log(`Registering subdomain: ${chalk_1.default.bold(options.subdomain)}...`);
30
+ socket.emit('register', options.subdomain);
31
+ });
32
+ socket.on('registered', (data) => {
33
+ console.log(chalk_1.default.green(`\nšŸŽ‰ Tunnel Live at: ${chalk_1.default.bold(data.url)}`));
34
+ console.log(chalk_1.default.yellow(`Waiting for requests...\n`));
35
+ });
36
+ socket.on('error', (msg) => {
37
+ console.error(chalk_1.default.red(`āŒ Error: ${msg}`));
38
+ process.exit(1);
39
+ });
40
+ socket.on("incoming-request", async (payload, callback) => {
41
+ const { method, path, body, headers } = payload;
42
+ console.log(chalk_1.default.blue(`šŸ“Ø ${method} ${path}`));
43
+ try {
44
+ delete headers["host"];
45
+ const response = await (0, axios_1.default)({
46
+ method: method,
47
+ url: `${LOCAL_TARGET}/${path}`,
48
+ headers: headers,
49
+ data: body,
50
+ validateStatus: () => true
51
+ });
52
+ console.log(chalk_1.default.green(` ↳ Forwarded Successfully (${response.status})`));
53
+ const responseToProxy = {
54
+ status: response.status,
55
+ headers: response.headers,
56
+ data: response.data
57
+ };
58
+ callback(responseToProxy);
59
+ }
60
+ catch (error) {
61
+ if (error instanceof Error) {
62
+ console.error(chalk_1.default.red(` ↳ Failed to connect to local app: ${error.message}`));
63
+ }
64
+ else {
65
+ console.error(chalk_1.default.red(` ↳ Failed to connect to local app: ${error}`));
66
+ }
67
+ const errorResponse = {
68
+ status: 502,
69
+ headers: {},
70
+ data: { error: "LocalLoop CLI could not reach your localhost server." }
71
+ };
72
+ callback(errorResponse);
73
+ }
74
+ });
75
+ socket.on('disconnect', () => {
76
+ console.log(chalk_1.default.red('\nšŸ”Œ Disconnected from Proxy. Retrying...'));
77
+ });
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "local-loop-by-ayan",
3
+ "version": "1.0.0",
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
+ "test": "echo \"Error: no test specified\" && exit 1"
16
+ },
17
+ "keywords": [
18
+ "tunnel",
19
+ "localhost",
20
+ "proxy"
21
+ ],
22
+ "author": "Your Name",
23
+ "license": "ISC",
24
+ "type": "commonjs",
25
+ "dependencies": {
26
+ "axios": "^1.13.2",
27
+ "chalk": "^4.1.2",
28
+ "commander": "^14.0.2",
29
+ "dotenv": "^17.2.3",
30
+ "socket.io-client": "^4.8.3"
31
+ },
32
+ "devDependencies": {
33
+ "@types/commander": "^2.12.0",
34
+ "@types/node": "^25.0.3",
35
+ "ts-node": "^10.9.2",
36
+ "typescript": "^5.9.3"
37
+ }
38
+ }