Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept a comma-separated list of ports to forward #16

Merged
merged 4 commits into from Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -67,6 +67,11 @@ OPTIONS
-r, --remote=remote git remote of app to use

DESCRIPTION
Provide a port or comma-separated list of ports to forward.

For example, "4000,9000:9001" will forward port 4000 to port 4000 and
port 9000 to port 9001.

Example:

$ heroku ps:forward 8080 --app murmuring-headland-14719
Expand Down
46 changes: 30 additions & 16 deletions commands/port.js
Expand Up @@ -16,7 +16,12 @@ module.exports = function(topic, command) {
topic: topic,
command: command,
description: 'Forward traffic on a local port to a dyno',
help: `Example:
help: `Provide a port or comma-separated list of ports to forward.

For example, "4000,9000:9001" will forward port 4000 to port 4000 and
port 9000 to port 9001.

Example:

$ heroku ps:forward 8080 --app murmuring-headland-14719`,
args: [{name: 'port', optional: false}],
Expand All @@ -31,24 +36,33 @@ module.exports = function(topic, command) {

function * run(context, heroku) {
yield exec.initFeature(context, heroku, function *(configVars) {
let remotePort = context.args.port;
let localPort = context.flags.localPort || remotePort;
jkutner marked this conversation as resolved.
Show resolved Hide resolved
const portMappings = context.args.port.split(',').map(function(portMapping) {
const ports = portMapping.split(':')
return [ports[0], ports[1] || ports[0]]
})

yield exec.createSocksProxy(context, heroku, configVars, function(dynoIp, dynoName, socksPort) {
cli.log(`Listening on ${cli.color.white.bold(localPort)} and forwarding to ${cli.color.white.bold(`${dynoName}:${remotePort}`)}`)
portMappings.forEach(function(portMapping) {
const localPort = portMapping[0]
const remotePort = portMapping[1]

cli.log(`Listening on ${cli.color.white.bold(localPort)} and forwarding to ${cli.color.white.bold(`${dynoName}:${remotePort}`)}`)

net.createServer(function(connIn) {
socks.connect({
host: '0.0.0.0',
port: remotePort,
proxyHost: '127.0.0.1',
proxyPort: socksPort,
auths: [ socks.auth.None() ]
}, function(socket) {
connIn.pipe(socket);
socket.pipe(connIn);
});
}).listen(localPort);
})

cli.log(`Use ${cli.color.magenta('CTRL+C')} to stop port fowarding`)
net.createServer(function(connIn) {
socks.connect({
host: '0.0.0.0',
port: remotePort,
proxyHost: '127.0.0.1',
proxyPort: socksPort,
auths: [ socks.auth.None() ]
}, function(socket) {
connIn.pipe(socket);
socket.pipe(connIn);
});
}).listen(localPort);
});
});
return new Promise(resolve => {})
Expand Down