Verificar se servidor já está rodando
This commit is contained in:
parent
2c7404443a
commit
f8adae2f47
1 changed files with 14 additions and 5 deletions
|
|
@ -143,10 +143,19 @@ gerar.then(() => {
|
||||||
.send(html404.replace("{ERRO}", `Página não encontrada: ${request.url}`));
|
.send(html404.replace("{ERRO}", `Página não encontrada: ${request.url}`));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const jaEstaRodando = fetch(`http://127.0.0.1:${PORTA}`)
|
||||||
|
.then(() => true)
|
||||||
|
.catch(() => false);
|
||||||
|
|
||||||
|
jaEstaRodando.then((jaEstaRodando) => {
|
||||||
|
!jaEstaRodando &&
|
||||||
fastify.listen({ port: Number(PORTA) }, (err, address) => {
|
fastify.listen({ port: Number(PORTA) }, (err, address) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log(
|
console.log(
|
||||||
`${new Date().toISOString()} Servidor ${PREFIXO} Rodando em ${address}`,
|
`${new Date().toISOString()} Servidor ${PREFIXO} Rodando em ${address}`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jaEstaRodando && console.log(`Servidor ${PREFIXO} já está rodando`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue