nit: ask user to modify devOptions.port when addr in use for dev (#347)

* nit: ask user to modify devOptions.port when addr in use for dev

* unnecessary import of red

* changeset
This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2021-06-09 13:48:25 -07:00 committed by GitHub
parent 26853fd2ec
commit 5fbc1cb641
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
nit: ask user to modify devOptions.port when addr in use for dev

View file

@ -101,9 +101,18 @@ export default async function dev(astroConfig: AstroConfig) {
});
const port = astroConfig.devOptions.port;
server.listen(port, hostname, () => {
const endServerTime = performance.now();
info(logging, 'dev server', green(`Server started in ${Math.floor(endServerTime - startServerTime)}ms.`));
info(logging, 'dev server', `${green('Local:')} http://${hostname}:${port}/`);
});
server
.listen(port, hostname, () => {
const endServerTime = performance.now();
info(logging, 'dev server', green(`Server started in ${Math.floor(endServerTime - startServerTime)}ms.`));
info(logging, 'dev server', `${green('Local:')} http://${hostname}:${port}/`);
})
.on('error', (err: NodeJS.ErrnoException) => {
if (err.code && err.code === 'EADDRINUSE') {
error(logging, 'dev server', `Address ${hostname}:${port} already in use. Try changing devOptions.port in your config file`);
} else {
error(logging, 'dev server', err.stack);
}
process.exit(1);
});
}