Skip to content

Commit

Permalink
fix: improve reconnection logic
Browse files Browse the repository at this point in the history
increase tests coverage
  • Loading branch information
stas-nc committed Jun 25, 2024
1 parent da6c228 commit 335d284
Show file tree
Hide file tree
Showing 24 changed files with 1,474 additions and 196 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/easy-tunnel-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
Expand All @@ -21,4 +21,16 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- name: Checkout server
uses: actions/checkout@v3
with:
repository: namecheap/mytunnel-server
ref: master
path: server
- name: Start server
run: |
npm ci
npm run dev &
npx -y wait-on tcp:8087 --log
working-directory: server
- run: npm test
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"arrowParens": "avoid",
"singleQuote": true,
"tabWidth": 2,
"printWidth": 120
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const easyTunnel = require('@namecheap/easy-tunnel');

- `port` (number) [required] The local port number to expose through easy-tunnel.
- `subdomain` (string) Request a specific subdomain on the proxy server. **Note** You may not actually receive this name depending on availability.
- `host` (string) URL for the upstream proxy server. Defaults to `https://localtunnel.me`.
- `host` (string) URL for the upstream proxy server. Defaults to `http://localhost:8087`.
- `local_host` (string) Proxy to this hostname instead of `localhost`. This will also cause the `Host` header to be re-written to this value in proxied requests.
- `local_https` (boolean) Enable tunneling to local HTTPS server.
- `local_cert` (string) Path to certificate PEM file for local HTTPS server.
Expand Down
21 changes: 16 additions & 5 deletions bin/et.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { argv } = yargs
.option('h', {
alias: 'host',
describe: 'Upstream server providing forwarding',
default: 'https://localtunnel.me',
default: 'http://localhost:8087',
})
.option('s', {
alias: 'subdomain',
Expand Down Expand Up @@ -50,11 +50,20 @@ const { argv } = yargs
describe: 'Print basic request info',
})
.option('request-secure-tunnel', {
describe: 'Requests tunel server to create secure tunnel if it is available.',
alias: 'secure',
describe: 'Requests tunnel server to create secure tunnel if it is available.',
})
.option('local_max_reconnect_count', {
.option('local-max-retries', {
describe: 'Max number of reconnection retries to local server if it goes offline.',
default: 90,
default: Infinity,
})
.option('connect-timeout', {
describe: 'Connection timeout (ms)',
default: 10_000,
})
.option('idle-timeout', {
describe: 'Idle socket timeout (ms)',
default: 15_000,
})
.require('port')
.boolean('local-https')
Expand Down Expand Up @@ -82,7 +91,9 @@ if (typeof argv.port !== 'number') {
local_ca: argv.localCa,
allow_invalid_cert: argv.allowInvalidCert,
request_secure_tunnel: argv.requestSecureTunnel,
local_max_reconnect_count: argv.local_max_reconnect_count
local_max_retries: argv.localMaxRetries,
connect_timeout: argv.connectTimeout,
idle_timeout: argv.idleTimeout
}).catch(err => {
throw err;
});
Expand Down
32 changes: 32 additions & 0 deletions cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-----BEGIN CERTIFICATE-----
MIIFmTCCA4GgAwIBAgIUN8ZRrUaNcWvSZUcrQODSzxj3tdUwDQYJKoZIhvcNAQEL
BQAwXDELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEVMBMGA1UEAwwMY2EubG9jYWxob3N0
MB4XDTI0MDYyNDE2NTM1MloXDTI1MDYyNDE2NTM1MlowXDELMAkGA1UEBhMCQVUx
EzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMg
UHR5IEx0ZDEVMBMGA1UEAwwMY2EubG9jYWxob3N0MIICIjANBgkqhkiG9w0BAQEF
AAOCAg8AMIICCgKCAgEAqvgDXnVfqT30mFY2Wg7cpeVBMZmW6/JiM8Ncu2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BtoZM8nZ7q+LqQmnEP+BFURG2Ht8i9mK+NHWfvUuZoyCaU
mhcG37+lGjRS8x94SgHFDKKsyeF7qI5RSuWSd4b/2/ZurW1Us9C03Evu2/dcHhku
eczKA9T0MM6ZrIPrzM7whNldLredJoai734Kzq1kkl6Z/lESy/dlXGBA+UgnGuP0
LQSmJ8RQis8k01nm4T0vht+7GYJ1QVzEB1I4/WVhjll6ig+s+Dvx8tT01nmxepxR
TjbFYVQuS3G9TWkP/OJm87sHZmYfDdVjQQlpSYaSQ2qEthVtmzTVg6r4FBxGErGL
6z7bNmqnpnrmCebjl+xoRwyatTLTZz/+lmtszYg+WhzEsy61PaU4fzF8y0VfncJ9
6dP0XP3CVgKjHIDM4Jsk6rDkzOc8yU3ESkcnCPCIJIQQtBk31EyKPRp4ALTK
-----END CERTIFICATE-----
3 changes: 2 additions & 1 deletion easyTunnel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ declare interface BootstrapOpts {
local_ca?: string;
allow_invalid_cert?: boolean;
request_secure_tunnel?: boolean;
local_max_reconnect_count?: number;
local_max_retries?: number;
local_reconnect_delay?: number;
}

declare const localtunnel: (opts: BootstrapOpts) => Promise<Tunnel>;
Expand Down
Loading

0 comments on commit 335d284

Please sign in to comment.