@@ -140,9 +140,11 @@ const hostname = "::";
140140const porta = process . env . PORT ;
141141
142142const 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" ) ;
146148const ano = date . getFullYear ( ) ;
147149
148150app . use ( express . urlencoded ( { extended : true } ) ) ;
@@ -153,15 +155,27 @@ applyAutoMiddlewares(app);
153155WSChat ( ) ; // starts HTTP + WS server on port 8080
154156
155157var 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+
165179function autoPages ( ) {
166180 const hostJson = fs . readFileSync ( "data/host.json" , "utf8" ) ;
167181 const hosts = JSON . parse ( hostJson ) ;
0 commit comments