Put id in path #171
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
= require(node:10.1.0-alpine
|
FROM node:10.1.0-alpine
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ The default localtunnel client connects to the `localtunnel.me` server. You can,
|
|||||||
* You can set up DNS entries for your `domain.tld` and `*.domain.tld` (or `sub.domain.tld` and `*.sub.domain.tld`).
|
* You can set up DNS entries for your `domain.tld` and `*.domain.tld` (or `sub.domain.tld` and `*.sub.domain.tld`).
|
||||||
* The server can accept incoming TCP connections for any non-root TCP port (i.e. ports over 1000).
|
* The server can accept incoming TCP connections for any non-root TCP port (i.e. ports over 1000).
|
||||||
|
|
||||||
The above are constant as the client will ask the server for a subdomain under a particular domain. The server will listen on any OS-assigned TCP port for client connections.
|
The above are important as the client will ask the server for a subdomain under a particular domain. The server will listen on any OS-assigned TCP port for client connections.
|
||||||
|
|
||||||
#### setup
|
#### setup
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -1,12 +1,12 @@
|
|||||||
#!/usr/bin/env node -r esm
|
#!/usr/bin/env node -r esm
|
||||||
|
|
||||||
require('localenv');
|
import 'localenv';
|
||||||
const optimist = require('optimist');
|
import optimist from 'optimist';
|
||||||
|
|
||||||
const log = require('book');
|
import log from 'book';
|
||||||
const Debug = require('debug');
|
import Debug from 'debug';
|
||||||
|
|
||||||
const CreateServer = require('../server');
|
import CreateServer from '../server';
|
||||||
|
|
||||||
const debug = Debug('localtunnel');
|
const debug = Debug('localtunnel');
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ const argv = optimist
|
|||||||
describe: 'IP address to bind to'
|
describe: 'IP address to bind to'
|
||||||
})
|
})
|
||||||
.options('domain', {
|
.options('domain', {
|
||||||
describe: 'Specify the base domain name. This is optional if hosting localtunnel = require(a regular example.com domain. This is required if hosting a localtunnel server = require(a subdomain (i.e. lt.example.dom where clients will be client-app.lt.example.come)',
|
describe: 'Specify the base domain name. This is optional if hosting localtunnel from a regular example.com domain. This is required if hosting a localtunnel server from a subdomain (i.e. lt.example.dom where clients will be client-app.lt.example.come)',
|
||||||
})
|
})
|
||||||
.options('max-sockets', {
|
.options('max-sockets', {
|
||||||
default: 10,
|
default: 10,
|
||||||
|
|||||||
+5
-5
@@ -1,7 +1,7 @@
|
|||||||
const http = require('http');
|
import http from 'http';
|
||||||
const Debug = require('debug');
|
import Debug from 'debug';
|
||||||
const pump = require('pump');
|
import pump from 'pump';
|
||||||
const EventEmitter = require('events');
|
import EventEmitter from 'events';
|
||||||
|
|
||||||
// A client encapsulates req/res handling using an agent
|
// A client encapsulates req/res handling using an agent
|
||||||
//
|
//
|
||||||
@@ -129,4 +129,4 @@ class Client extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Client;
|
export default Client;
|
||||||
+6
-6
@@ -1,10 +1,10 @@
|
|||||||
const assert = require('assert';
|
import assert from 'assert';
|
||||||
const http = require('http';
|
import http from 'http';
|
||||||
const { Duplex } = require('stream';
|
import { Duplex } from 'stream';
|
||||||
const WebSocket = require('ws';
|
import WebSocket from 'ws';
|
||||||
const net = require('net';
|
import net from 'net';
|
||||||
|
|
||||||
const Client = require('./Client';
|
import Client from './Client';
|
||||||
|
|
||||||
class DummySocket extends Duplex {
|
class DummySocket extends Duplex {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const { hri } = require('human-readable-ids');
|
import { hri } from 'human-readable-ids';
|
||||||
const Debug = require('debug');
|
import Debug from 'debug';
|
||||||
|
|
||||||
const Client = require('./Client');
|
import Client from './Client';
|
||||||
const TunnelAgent = require('./TunnelAgent');
|
import TunnelAgent from './TunnelAgent';
|
||||||
|
|
||||||
// Manage sets of clients
|
// Manage sets of clients
|
||||||
//
|
//
|
||||||
@@ -93,4 +93,4 @@ class ClientManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ClientManager;
|
export default ClientManager;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const assert = require('assert';
|
import assert from 'assert';
|
||||||
const net = require('net';
|
import net from 'net';
|
||||||
|
|
||||||
const ClientManager = require('./ClientManager';
|
import ClientManager from './ClientManager';
|
||||||
|
|
||||||
describe('ClientManager', () => {
|
describe('ClientManager', () => {
|
||||||
it('should construct with no tunnels', () => {
|
it('should construct with no tunnels', () => {
|
||||||
|
|||||||
+12
-12
@@ -1,8 +1,8 @@
|
|||||||
const { Agent } = require('http');
|
import { Agent } from 'http';
|
||||||
const net = require('net');
|
import net from 'net';
|
||||||
const assert = require('assert');
|
import assert from 'assert';
|
||||||
const log = require('book');
|
import log from 'book';
|
||||||
const Debug = require('debug');
|
import Debug from 'debug';
|
||||||
|
|
||||||
const DEFAULT_MAX_SOCKETS = 10;
|
const DEFAULT_MAX_SOCKETS = 10;
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ class TunnelAgent extends Agent {
|
|||||||
super({
|
super({
|
||||||
keepAlive: true,
|
keepAlive: true,
|
||||||
// only allow keepalive to hold on to one socket
|
// only allow keepalive to hold on to one socket
|
||||||
// this prevents it = require(holding on to all the sockets so they can be used for upgrades
|
// this prevents it from holding on to all the sockets so they can be used for upgrades
|
||||||
maxFreeSockets: 1,
|
maxFreeSockets: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ class TunnelAgent extends Agent {
|
|||||||
server.on('close', this._onClose.bind(this));
|
server.on('close', this._onClose.bind(this));
|
||||||
server.on('connection', this._onConnection.bind(this));
|
server.on('connection', this._onConnection.bind(this));
|
||||||
server.on('error', (err) => {
|
server.on('error', (err) => {
|
||||||
// These errors happen = require(killed connections, we don't worry about them
|
// These errors happen from killed connections, we don't worry about them
|
||||||
if (err.code == 'ECONNRESET' || err.code == 'ETIMEDOUT') {
|
if (err.code == 'ECONNRESET' || err.code == 'ETIMEDOUT') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ class TunnelAgent extends Agent {
|
|||||||
this.emit('end');
|
this.emit('end');
|
||||||
}
|
}
|
||||||
|
|
||||||
// new socket connection = require(client for tunneling requests to client
|
// new socket connection from client for tunneling requests to client
|
||||||
_onConnection(socket) {
|
_onConnection(socket) {
|
||||||
// no more socket connections allowed
|
// no more socket connections allowed
|
||||||
if (this.connectedSockets >= this.maxTcpSockets) {
|
if (this.connectedSockets >= this.maxTcpSockets) {
|
||||||
@@ -98,7 +98,7 @@ class TunnelAgent extends Agent {
|
|||||||
socket.once('close', (hadError) => {
|
socket.once('close', (hadError) => {
|
||||||
this.debug('closed socket (error: %s)', hadError);
|
this.debug('closed socket (error: %s)', hadError);
|
||||||
this.connectedSockets -= 1;
|
this.connectedSockets -= 1;
|
||||||
// remove the socket = require(available list
|
// remove the socket from available list
|
||||||
const idx = this.availableSockets.indexOf(socket);
|
const idx = this.availableSockets.indexOf(socket);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
this.availableSockets.splice(idx, 1);
|
this.availableSockets.splice(idx, 1);
|
||||||
@@ -113,7 +113,7 @@ class TunnelAgent extends Agent {
|
|||||||
|
|
||||||
// close will be emitted after this
|
// close will be emitted after this
|
||||||
socket.once('error', (err) => {
|
socket.once('error', (err) => {
|
||||||
// we do not log these errors, sessions can drop = require(clients for many reasons
|
// we do not log these errors, sessions can drop from clients for many reasons
|
||||||
// these are not actionable errors for our server
|
// these are not actionable errors for our server
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
});
|
});
|
||||||
@@ -139,7 +139,7 @@ class TunnelAgent extends Agent {
|
|||||||
this.availableSockets.push(socket);
|
this.availableSockets.push(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch a socket = require(the available socket pool for the agent
|
// fetch a socket from the available socket pool for the agent
|
||||||
// if no socket is available, queue
|
// if no socket is available, queue
|
||||||
// cb(err, socket)
|
// cb(err, socket)
|
||||||
createConnection(options, cb) {
|
createConnection(options, cb) {
|
||||||
@@ -172,4 +172,4 @@ class TunnelAgent extends Agent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = TunnelAgent;
|
export default TunnelAgent;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const http = require('http';
|
import http from 'http';
|
||||||
const net = require('net';
|
import net from 'net';
|
||||||
const assert = require('assert';
|
import assert from 'assert';
|
||||||
|
|
||||||
const TunnelAgent = require('./TunnelAgent';
|
import TunnelAgent from './TunnelAgent';
|
||||||
|
|
||||||
describe('TunnelAgent', () => {
|
describe('TunnelAgent', () => {
|
||||||
it('should create an empty agent', async () => {
|
it('should create an empty agent', async () => {
|
||||||
|
|||||||
Generated
-3619
File diff suppressed because it is too large
Load Diff
@@ -1,16 +1,16 @@
|
|||||||
const log = require('book');
|
import log from 'book';
|
||||||
const Koa = require('koa');
|
import Koa from 'koa';
|
||||||
const tldjs = require('tldjs');
|
import tldjs from 'tldjs';
|
||||||
const Debug = require('debug');
|
import Debug from 'debug';
|
||||||
const http = require('http');
|
import http from 'http';
|
||||||
const { hri } = require('human-readable-ids');
|
import { hri } from 'human-readable-ids';
|
||||||
const Router = require('koa-router');
|
import Router from 'koa-router';
|
||||||
|
|
||||||
const ClientManager = require('./lib/ClientManager');
|
import ClientManager from './lib/ClientManager';
|
||||||
|
|
||||||
const debug = Debug('localtunnel:server');
|
const debug = Debug('localtunnel:server');
|
||||||
|
|
||||||
module.exports = function(opt) {
|
export default function(opt) {
|
||||||
opt = opt || {};
|
opt = opt || {};
|
||||||
|
|
||||||
const validHosts = (opt.domain) ? [opt.domain] : undefined;
|
const validHosts = (opt.domain) ? [opt.domain] : undefined;
|
||||||
|
|||||||
+6
-6
@@ -1,10 +1,10 @@
|
|||||||
const request = require('supertest';
|
import request from 'supertest';
|
||||||
const assert = require('assert';
|
import assert from 'assert';
|
||||||
const { Server as WebSocketServer } = require('ws';
|
import { Server as WebSocketServer } from 'ws';
|
||||||
const WebSocket = require('ws';
|
import WebSocket from 'ws';
|
||||||
const net = require('net';
|
import net from 'net';
|
||||||
|
|
||||||
const createServer = require('./server';
|
import createServer from './server';
|
||||||
|
|
||||||
describe('Server', () => {
|
describe('Server', () => {
|
||||||
it('server starts and stops', async () => {
|
it('server starts and stops', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user