cm-tunnel 1.1.0 → 1.2.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.
- package/README.md +7 -3
- package/dist/Provider.d.ts +1 -0
- package/dist/Tunnel.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -2
- package/dist/providers/ngrok.d.ts +8 -0
- package/dist/providers/ngrok.js +44 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# cm-tunnel
|
|
2
2
|
|
|
3
|
-
Exponha seu servidor HTTP local para a internet através de uma API extremamente simples. Suporta **Cloudflare** e **
|
|
3
|
+
Exponha seu servidor HTTP local para a internet através de uma API extremamente simples. Suporta **Cloudflare**, **LocalTunnel** e **Ngrok**.
|
|
4
4
|
|
|
5
5
|
## Instalação
|
|
6
6
|
|
|
@@ -23,9 +23,10 @@ import tunnel from 'cm-tunnel';
|
|
|
23
23
|
|
|
24
24
|
try {
|
|
25
25
|
const t = await tunnel({
|
|
26
|
-
provider: 'cloudflare', //
|
|
26
|
+
provider: 'cloudflare', // 'cloudflare', 'localtunnel' ou 'ngrok'
|
|
27
27
|
port: 3000,
|
|
28
|
-
subdomain: 'meu-app-unico', // Opcional (
|
|
28
|
+
subdomain: 'meu-app-unico', // Opcional (para localtunnel e ngrok)
|
|
29
|
+
authtoken: 'token_aqui', // Opcional (recomendado para ngrok)
|
|
29
30
|
rateLimit: { // Opcional: Bloqueia IPs por excesso de requisições
|
|
30
31
|
maxRequestsPerMinute: 60,
|
|
31
32
|
routes: ['/api/'] // Se vazio, aplica globalmente
|
|
@@ -53,6 +54,9 @@ const t1 = await tunnel.cloudflare({ port: 3000 });
|
|
|
53
54
|
|
|
54
55
|
// Usando localtunnel
|
|
55
56
|
const t2 = await tunnel.localtunnel({ port: 3000 });
|
|
57
|
+
|
|
58
|
+
// Usando ngrok
|
|
59
|
+
const t3 = await tunnel.ngrok({ port: 3000, authtoken: 'seu_token' });
|
|
56
60
|
```
|
|
57
61
|
|
|
58
62
|
## Objeto de Retorno
|
package/dist/Provider.d.ts
CHANGED
package/dist/Tunnel.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ interface TunnelAPI {
|
|
|
4
4
|
(options: TunnelOptions): Promise<TunnelInstance>;
|
|
5
5
|
cloudflare: (options: OmitProvider<TunnelOptions>) => Promise<TunnelInstance>;
|
|
6
6
|
localtunnel: (options: OmitProvider<TunnelOptions>) => Promise<TunnelInstance>;
|
|
7
|
+
ngrok: (options: OmitProvider<TunnelOptions>) => Promise<TunnelInstance>;
|
|
7
8
|
}
|
|
8
9
|
declare const tunnel: TunnelAPI;
|
|
9
10
|
export default tunnel;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createTunnel } from "./Tunnel.js";
|
|
2
2
|
const tunnel = createTunnel;
|
|
3
|
-
tunnel.cloudflare = (options) => createTunnel({ ...options, provider:
|
|
4
|
-
tunnel.localtunnel = (options) => createTunnel({ ...options, provider:
|
|
3
|
+
tunnel.cloudflare = (options) => createTunnel({ ...options, provider: 'cloudflare' });
|
|
4
|
+
tunnel.localtunnel = (options) => createTunnel({ ...options, provider: 'localtunnel' });
|
|
5
|
+
tunnel.ngrok = (options) => createTunnel({ ...options, provider: 'ngrok' });
|
|
5
6
|
export default tunnel;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import ngrok from '@ngrok/ngrok';
|
|
2
|
+
import { Provider } from '../Provider.js';
|
|
3
|
+
export default class NgrokProvider extends Provider {
|
|
4
|
+
url = null;
|
|
5
|
+
listener = null;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options);
|
|
8
|
+
}
|
|
9
|
+
start() {
|
|
10
|
+
return new Promise(async (resolve, reject) => {
|
|
11
|
+
try {
|
|
12
|
+
if (this.options.authtoken) {
|
|
13
|
+
ngrok.authtoken(this.options.authtoken);
|
|
14
|
+
}
|
|
15
|
+
this.listener = await ngrok.forward({ addr: this.port, authtoken: this.options.authtoken, domain: this.options.subdomain });
|
|
16
|
+
this.url = this.listener.url() || null;
|
|
17
|
+
if (!this.url) {
|
|
18
|
+
return reject(new Error('Falha ao obter URL do Ngrok.'));
|
|
19
|
+
}
|
|
20
|
+
this.emit('ready', this.url);
|
|
21
|
+
resolve({
|
|
22
|
+
provider: 'ngrok',
|
|
23
|
+
url: this.url,
|
|
24
|
+
port: this.port,
|
|
25
|
+
stop: this.stop.bind(this),
|
|
26
|
+
process: this.listener,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
reject(new Error(`Falha ao iniciar o túnel Ngrok: ${err.message}`));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
stop() {
|
|
35
|
+
if (this.listener) {
|
|
36
|
+
this.listener.close().then(() => {
|
|
37
|
+
this.emit('close');
|
|
38
|
+
}).catch((err) => {
|
|
39
|
+
this.emit('error', err);
|
|
40
|
+
});
|
|
41
|
+
this.listener = null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cm-tunnel",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Exponha seu servidor HTTP local para a internet através do Cloudflare ou LocalTunnel de forma simples",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"LICENSE"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
+
"@ngrok/ngrok": "^1.7.0",
|
|
52
53
|
"bancoz": "^2.2.8",
|
|
53
54
|
"http-proxy": "^1.18.1",
|
|
54
55
|
"localtunnel": "^2.0.2"
|