From f8adae2f47002f01996eeadbe767d9727253d370 Mon Sep 17 00:00:00 2001 From: Luiz Silva Date: Mon, 12 Aug 2024 14:00:52 -0300 Subject: [PATCH] =?UTF-8?q?Verificar=20se=20servidor=20j=C3=A1=20est=C3=A1?= =?UTF-8?q?=20rodando?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ferramentas/rodar_servidor.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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`); }); });