Closed CordonZeus22 closed 9 months ago
You know when the server closes either by catching exception or successfully getting the code so you can implement your own logging in that case.
As for disabling/changing the logger I think more universal would be adding onstart
callback so you can execute any code you want on server startup. There is only one console.log in the code so I don't think logger changing would be that needed.
export async function listenForCode(_serverConfig: Partial<ServerConfigType> = {}, onstart?:(host:string, port:number)=>any): Promise<string> {
const serverConfig: ServerConfigType = {port: 8080, host: "localhost", timeout: 30 * 1000, ..._serverConfig}
const server = await createServer(serverConfig);
if (onstart){
onstart(serverConfig.host, serverConfig.port)
}else{
console.log(`MS Token Server is running on http://${serverConfig.host}:${serverConfig.port}`);
}
return _listenForCode(server, serverConfig);
}
I'm ok with that, but if an onstart
callback is added, why don't add an onclose
callback ? I think it's more logic than awaiting the result for knowing the state of the server cause it can be handled with the close
event of the server. For the code you send, the log isn't in the createServer
function and called by the callback of the listen
method ?
Take a look on #21. I've added onstart, onclose and oncode callbacks
For onstart
callback, why don't use the callback of the listen
method like before ? For onclose
callback, I thought use the close
event from the server. I have pushed that on my fork if you want to check https://github.com/dommilosz/minecraft-auth/compare/pr-issue-20...CordonZeus22:minecraft-auth:pr-issue-20
Would it be possible to add an option for disable the logs or use a custom function to be used instead of the
console.log
?Also, would it be possible to add a log when the MS Token Server is close ?