Use a unique port for serving the presentation
Opened this issue · 6 comments
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?
@hsablonniere We should do the same in the generator.
What's a 4-digit number that means "I'm a presentation"? 1337 has been suggested for JHipster. Angular CLI uses 4200.
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 ;)
BTW, it would be nice to have it in a variable on top of the gulpfile.
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
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