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

Use a unique port for serving the presentation #7

Open
mojavelinux opened this issue Nov 30, 2016 · 6 comments
Open

Use a unique port for serving the presentation #7

mojavelinux opened this issue Nov 30, 2016 · 6 comments

Comments

@mojavelinux
Copy link
Member

Both ports 8080 and 8000 are commonly used for web and application servers. There's no reason we should have to use either of these ports by default. Let's pick a unique "Bespoke" port and make that the default. Suggestions?

@mojavelinux
Copy link
Member Author

@hsablonniere We should do the same in the generator.

@mraible
Copy link

mraible commented Dec 1, 2016

What's a 4-digit number that means "I'm a presentation"? 1337 has been suggested for JHipster. Angular CLI uses 4200.

@mojavelinux
Copy link
Member Author

Neat way to look at it!

For no particular reason, I like these numbers:

  • 4092 - an occasional glitch in the game The Legend of Zelda: Ocarina of Time causes the Gossip Stones to say this number (this could play off our our SNES theme)
  • 7070
  • 4321 (middleman uses 4567, which is the opposite direction; but used by remote whois service)
  • 7744
  • 8128 (perfect number)
  • 8833
  • 4400

I don't want to overthink this, so let's try to arrive at something fairly soon ;)

@hasalex
Copy link
Contributor

hasalex commented Dec 1, 2016

BTW, it would be nice to have it in a variable on top of the gulpfile.

@hsablonniere
Copy link

Hey!

I've been playing with this problem on an old side project. The solution we used in the end felt very nice : port chosen between 10000 and 19999 using the absolute path of the presentation on filesystem.

This is done like this :

// module
const MIN_PORT = 10000
const MAX_PORT = 19999
const PORT_SPREAD = MAX_PORT - MIN_PORT

function pathToPort() {

    // you need a sha1 (or other) function
    const sha1Path = sha1(process.cwd())
    const bigNumber = parseInt(sha1Path, 16)

    const integer = bigNumber % portSpread

    return minPort + integer
}

// usage
const port = pathToPort()

There's a log of params that can be changed, WDYT?

Cons :

  • What do we do if it stumbles upon an already used port?

Pros :

  • You can start several presentations at the same time without conflict
  • You're sure that a given presentation on your FS will always have the same port

@mojavelinux
Copy link
Member Author

I like the idea of a randomly chosen port, but I don't like ports that high. I think they are hard to read and remember. We should pick ports either from 4000 - 9999 IMHO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants