Skip to content

Commit c956609

Browse files
fixed bugs
1 parent 383b1dd commit c956609

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

package-lock.json

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ const hostname = "::";
140140
const porta = process.env.PORT;
141141

142142
const date = new Date();
143-
const dia = date.getDate().toString().padStart(2, "0") - 1;
144-
const dia7 = (date.getDate() - 7).toString().padStart(2, "0") - 1;
145-
const mes = (date.getMonth() + 1).toString().padStart(2, "0");
143+
const diaNumber = date.getDate() - 1; // número, sem transformar em string ainda
144+
const dia = String(diaNumber).padStart(2, "0"); // agora formata com padStart
145+
const dia7Number = date.getDate() - 7;
146+
const dia7 = String(dia7Number).padStart(2, "0");
147+
const mes = String(date.getMonth() + 1).padStart(2, "0");
146148
const ano = date.getFullYear();
147149

148150
app.use(express.urlencoded({ extended: true }));
@@ -153,15 +155,27 @@ applyAutoMiddlewares(app);
153155
WSChat(); // starts HTTP + WS server on port 8080
154156

155157
var server = app.listen(porta || 0, hostname, function () {
158+
// Corrige: server.address() pode ser null se o bind falhar
156159
const addr = server.address();
160+
161+
if (!addr) {
162+
console.warn("⚠️ Falha ao obter endereço do servidor (server.address() retornou null)");
163+
console.warn("Verifique se a porta já está em uso ou se o IPv6 está ativado.");
164+
return;
165+
}
166+
157167
const host = addr.address;
158168
const port = addr.port;
159169

170+
// Ajuste: se for IPv6, exibir com colchetes [::1]
171+
const displayHost = host.includes(":") ? `[${host}]` : host;
172+
160173
console.log("Servidor rodando em http://%s:%s", hostname, port);
161-
console.log("IP Obtido: http://%s:%s", host, port);
174+
console.log("IP Obtido: http://%s:%s", displayHost, port);
162175
discordLogs("START", `Servidor rodando em http://${hostname}:${port}`);
163176
});
164177

178+
165179
function autoPages() {
166180
const hostJson = fs.readFileSync("data/host.json", "utf8");
167181
const hosts = JSON.parse(hostJson);

0 commit comments

Comments
 (0)