-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
Suggest preact commands to run dev server on new port if 8080 is already being used #179
Comments
preact watch
to run dev server on new port if 8080 is already being used
This would be a great addition. I have some code snippets I can paste here if you need it |
Cool, I'd love it |
this time, it's 3 lines const getPort = require("get-port")
getPort(3000).then(port => {
console.log(port);
// Will use 3000 if available, otherwise fall back to a random port
}); if 3000 !== port, then ask user if they want to spawn in other port. |
We can always simply spawn http server using |
@rkostrzewski that's what 'use strict';
const net = require('net');
const getPort = port => new Promise((resolve, reject) => {
const server = net.createServer();
server.unref();
server.on('error', reject);
server.listen(port, () => {
const port = server.address().port;
server.close(() => {
resolve(port);
});
});
});
module.exports = preferredPort => preferredPort ?
getPort(preferredPort).catch(() => getPort(0)) :
getPort(0); |
CRA does this in a pretty nice way !! I would just take the handling of PORT from CRA and use it here !! That is fine right? |
We can use the popular get-port module to handle this: getPort(3000).then(port => {
console.log(port);
// Will use 3000 if available, otherwise fall back to a random port
}); |
@thangngoc89 I didn't see that require call 😆 |
@developit I talked about this and no one listen #179 (comment) |
okay, so |
Whoops, forgot to read the whole thread @thangngoc89 - sorry about that! I like that |
I think we should always be running a random port (if 8080 is taken). If a user passes |
@lukeed I saw a discussions about this between @-gaearon and others. From UX pov, we should not spawn in random port (if 8080 is taken). Because users might spawning it in other terminal tab. instead, ask user what to do |
Okay 👍 Just reciting from what I've seen & have liked personally. Sounds good either way |
Any thoughts? |
@reznord What do you mean by free port? get-port return a new port in case preferred port was occupied |
Oh, I didn't know this. Then we can go with get-port itself. |
As of now, when we run a dev server using
preact serve
orpreact watch
by default opens on8080
port.If there is a process which runs on
8080
already, preact doesn't ask the user whether he wants to run on a new port. As of now it terminates the process.It would be great if we can suggest the CLI to ask the user whether he wants to run on a different port.
The text was updated successfully, but these errors were encountered: