Skip to content

Commit

Permalink
refactor(logs): one log per action
Browse files Browse the repository at this point in the history
  • Loading branch information
syroegkin committed May 24, 2023
1 parent 443ce0b commit 51951b7
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/nxtp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,20 @@ function sockerWritePromise(

export function nxtp(socket: net.Socket) {
const { remoteAddress } = socket;
console.log(`${remoteAddress}: new client connected`);

socket.on('data', async (data: Buffer) => {
try {
// Process request
const nxtpTimezone = processRequest(data);
console.log(`${remoteAddress}: Requesting time for ${nxtpTimezone}`);
// Convert timezone to IANA
const iana = nxtpToIana(nxtpTimezone);
console.log(`${remoteAddress}: transformed to ${iana}`);
// Generate response
const response = generateResponse(iana);
// Send response
await sockerWritePromise(socket, response);
// Close socket
socket.destroy();
console.log(`${remoteAddress}: close connection`);
console.log(`${remoteAddress}: Requested time for ${nxtpTimezone}, resolved to ${iana}`);
} catch (e: unknown) {
console.log(`${remoteAddress}: ${(e as Error).message}`);
socket.destroy();
Expand Down

0 comments on commit 51951b7

Please sign in to comment.