@jebcode-dev/jebcode-tunnel 1.0.4 → 1.0.7

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 (3) hide show
  1. package/README.md +1 -1
  2. package/index.js +27 -37
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -68,4 +68,4 @@ npm link
68
68
 
69
69
  ---
70
70
  © 2026 JEBCODE SOFTWARE E TECNOLOGIA LTDA.
71
- **JebCode Infrastructure v1.0.3**
71
+ **JebCode Infrastructure v1.0.6**
package/index.js CHANGED
@@ -131,37 +131,45 @@ function startTunnel(port, options = {}) {
131
131
  process.exit(1);
132
132
  }
133
133
 
134
- const subdomain = options.subdomain || "dev";
134
+ const subdomain = options.subdomain || null; // Se for null, o servidor gera um automático
135
135
  const insecure = options.insecure || false;
136
136
 
137
137
  process.stdout.write(chalk.blue(" ☁ Conectando à infraestrutura JebCode... "));
138
138
 
139
139
  const socket = io(SERVER_URL, {
140
- transports: ["websocket", "polling"],
141
- reconnectionAttempts: 10,
142
- timeout: 15000,
143
- rejectUnauthorized: !insecure,
144
- pingInterval: 10000,
145
- pingTimeout: 5000
140
+ transports: ["websocket"], // FORÇA WEBSOCKET (Mais estável que polling)
141
+ reconnection: true,
142
+ reconnectionAttempts: Infinity,
143
+ reconnectionDelay: 1000,
144
+ reconnectionDelayMax: 5000,
145
+ timeout: 20000, // Mais tempo para o handshake
146
+ rejectUnauthorized: !insecure
146
147
  });
147
148
 
148
149
  socket.on("connect", () => {
149
150
  process.stdout.write(chalk.green("OK\n"));
150
- socket.emit("authenticate", { token: config.token, subdomain });
151
+ socket.emit("authenticate", { token: config.token, subdomain, port });
151
152
  });
152
153
 
154
+ let hasShownHeader = false;
153
155
  socket.on("auth_result", (result) => {
154
156
  if (result.success) {
155
- console.clear();
156
- console.log(getHeader());
157
- console.log(chalk.white(" STATUS DO TÚNEL ATIVO"));
158
- console.log(chalk.blue(" ▪"), chalk.bold("URL Pública: "), chalk.yellow(`https://${subdomain}.jebcodetunnel.com`));
159
- console.log(chalk.blue(" ▪"), chalk.bold("Encaminhando:"), chalk.white(`http://localhost:${port}`), chalk.gray("➔"), chalk.cyan("jeb-gateway"));
160
- console.log(chalk.blue(" ▪"), chalk.bold("Dashboard: "), chalk.gray(`${SERVER_URL}/dashboard`));
161
-
162
- console.log(chalk.gray("\n Pressione CTRL+C para encerrar o túnel"));
163
- console.log(chalk.white("\n LOGS DE TRÁFEGO EM TEMPO REAL:"));
164
- console.log(chalk.gray(" " + "─".repeat(60)));
157
+ const finalSubdomain = result.subdomain || subdomain;
158
+ if (!hasShownHeader) {
159
+ console.clear();
160
+ console.log(getHeader());
161
+ console.log(chalk.white(" STATUS DO TÚNEL ATIVO"));
162
+ console.log(chalk.blue(" ▪"), chalk.bold("URL Pública: "), chalk.yellow(`https://${finalSubdomain}.jebcodetunnel.com`));
163
+ console.log(chalk.blue(" ▪"), chalk.bold("Encaminhando:"), chalk.white(`http://localhost:${port}`), chalk.gray("➔"), chalk.cyan(`${finalSubdomain}.jebcodetunnel.com`));
164
+ console.log(chalk.blue(" ▪"), chalk.bold("Dashboard: "), chalk.gray(`${SERVER_URL}/dashboard`));
165
+
166
+ console.log(chalk.gray("\n Pressione CTRL+C para encerrar o túnel"));
167
+ console.log(chalk.white("\n LOGS DE TRÁFEGO EM TEMPO REAL:"));
168
+ console.log(chalk.gray(" " + "─".repeat(60)));
169
+ hasShownHeader = true;
170
+ } else {
171
+ console.log(chalk.green("\n ✔ Conexão Restabelecida!"));
172
+ }
165
173
  } else {
166
174
  console.log(chalk.red("\n ✖ Falha na Autenticação:"), chalk.bold(result.message));
167
175
  console.log(chalk.gray(" Verifique seu token e se o subdomínio foi criado no dashboard.\n"));
@@ -176,12 +184,8 @@ function startTunnel(port, options = {}) {
176
184
  socket.on("incoming_request", async (reqData) => {
177
185
  const timestamp = new Date().toLocaleTimeString();
178
186
  const methodColor = reqData.method === "GET" ? chalk.green : reqData.method === "POST" ? chalk.blue : chalk.yellow;
179
-
180
- // Log imediato para feedback instantâneo no terminal
181
- const startLog = `${chalk.gray(` [${timestamp}]`)} ${methodColor(reqData.method.padEnd(7))} ${chalk.white(reqData.path.substring(0, 30).padEnd(30))} ${chalk.yellow("PROCESSANDO...")}`;
182
- process.stdout.write(startLog);
183
-
184
187
  const startTime = Date.now();
188
+
185
189
  try {
186
190
  const response = await axios({
187
191
  method: reqData.method,
@@ -196,14 +200,6 @@ function startTunnel(port, options = {}) {
196
200
  const duration = Date.now() - startTime;
197
201
  const statusColor = response.status < 300 ? chalk.green : response.status < 400 ? chalk.cyan : chalk.red;
198
202
 
199
- // Limpa a linha atual e sobrescreve com o log final
200
- if (process.stdout.isTTY) {
201
- process.stdout.clearLine(0);
202
- process.stdout.cursorTo(0);
203
- } else {
204
- process.stdout.write("\n");
205
- }
206
-
207
203
  const logLine = [
208
204
  chalk.gray(` [${timestamp}]`),
209
205
  methodColor(reqData.method.padEnd(7)),
@@ -221,12 +217,6 @@ function startTunnel(port, options = {}) {
221
217
  });
222
218
  } catch (err) {
223
219
  const duration = Date.now() - startTime;
224
- if (process.stdout.isTTY) {
225
- process.stdout.clearLine(0);
226
- process.stdout.cursorTo(0);
227
- } else {
228
- process.stdout.write("\n");
229
- }
230
220
  console.log(`${chalk.gray(` [${timestamp}]`)} ${methodColor(reqData.method.padEnd(7))} ${chalk.white(reqData.path.substring(0, 30).padEnd(30))} ${chalk.red("FALHOU")} ${chalk.gray(`${duration}ms`)}`);
231
221
 
232
222
  socket.emit(`response_${reqData.id}`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jebcode-dev/jebcode-tunnel",
3
- "version": "1.0.4",
3
+ "version": "1.0.7",
4
4
  "description": "CLI do JebCode Tunnel",
5
5
  "license": "MIT",
6
6
  "publishConfig": {