diff --git a/ferramentas/rodar_servidor.tsx b/ferramentas/rodar_servidor.tsx index 38959cb..e3a9c71 100644 --- a/ferramentas/rodar_servidor.tsx +++ b/ferramentas/rodar_servidor.tsx @@ -143,10 +143,19 @@ gerar.then(() => { .send(html404.replace("{ERRO}", `Página não encontrada: ${request.url}`)); }); - fastify.listen({ port: Number(PORTA) }, (err, address) => { - if (err) throw err; - console.log( - `${new Date().toISOString()} Servidor ${PREFIXO} Rodando em ${address}`, - ); + const jaEstaRodando = fetch(`http://127.0.0.1:${PORTA}`) + .then(() => true) + .catch(() => false); + + jaEstaRodando.then((jaEstaRodando) => { + !jaEstaRodando && + fastify.listen({ port: Number(PORTA) }, (err, address) => { + if (err) throw err; + console.log( + `${new Date().toISOString()} Servidor ${PREFIXO} Rodando em ${address}`, + ); + }); + + jaEstaRodando && console.log(`Servidor ${PREFIXO} já está rodando`); }); });