@aimee-blue/ab-service-kit
Version:
Aimee Blue Service Template
1 lines • 2.29 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/shared/sockets/logConnected.ts"],"names":["logConnected","logger","socket","message","epic","forwardedFor","headers","remoteAddress","connection","info","logOnConnection","e","error","log","EOL","id","url","name","timestamp"],"mappings":";;;;;;;AAAA;;AAGA;;AAEA;;AAEO,MAAMA,YAAY,GAAG,CAC1BC,MAD0B,EAE1BC,MAF0B,EAG1BC,OAH0B,EAI1BC,IAJ0B,KAKvB;AACH,QAAMC,YAAY,GAAGF,OAAO,CAACG,OAAR,CAAgB,iBAAhB,CAArB;AACA,QAAMC,aAAa,GAAGJ,OAAO,CAACK,UAAR,CAAmBD,aAAzC;AAEA,MAAIE,IAAI,GAAG,EAAX;;AACA,MAAIL,IAAI,CAACM,eAAT,EAA0B;AACxB,QAAI;AACFD,MAAAA,IAAI,GAAGL,IAAI,CAACM,eAAL,CAAqBR,MAArB,EAA6BC,OAA7B,CAAP;AACD,KAFD,CAEE,OAAOQ,CAAP,EAAU;AACV,wCAAcA,CAAd;AACAV,MAAAA,MAAM,CAACW,KAAP,CACE,sFADF,EAEED,CAFF;AAID;AACF;;AAEDV,EAAAA,MAAM,CAACY,GAAP,CACG,GAAEC,OAAI,qBADT,EAEE;AACEC,IAAAA,EAAE,EAAEZ,OAAO,CAACY,EADd;AAEEC,IAAAA,GAAG,EAAEb,OAAO,CAACa,GAFf;AAGEZ,IAAAA,IAAI,EAAEA,IAAI,CAACa,IAHb;AAIEC,IAAAA,SAAS,EAAE,qBAJb;AAKE,QAAIb,YAAY,IAAI;AAClBA,MAAAA;AADkB,KAApB,CALF;AAQE,QAAIE,aAAa,IAAI;AACnBA,MAAAA;AADmB,KAArB,CARF;AAWE,OAAGE;AAXL,GAFF,EAeEK,OAfF;AAiBD,CAvCM","sourcesContent":["import { EOL } from 'os';\nimport { SocketWithInfo, MessageWithInfo } from './types';\nimport { AnySocketEpic } from '../kit';\nimport { registerError } from '../registerError';\nimport { Logger } from '../logging';\nimport { localNow } from '../time';\n\nexport const logConnected = (\n logger: Logger,\n socket: SocketWithInfo,\n message: MessageWithInfo,\n epic: AnySocketEpic\n) => {\n const forwardedFor = message.headers['x-forwarded-for'];\n const remoteAddress = message.connection.remoteAddress;\n\n let info = {};\n if (epic.logOnConnection) {\n try {\n info = epic.logOnConnection(socket, message);\n } catch (e) {\n registerError(e);\n logger.error(\n '💥 Couldnt get information for logging (your custom SocketEpic.logInfo has thrown!)',\n e\n );\n }\n }\n\n logger.log(\n `${EOL}✊ Client connected`,\n {\n id: message.id,\n url: message.url,\n epic: epic.name,\n timestamp: localNow(),\n ...(forwardedFor && {\n forwardedFor,\n }),\n ...(remoteAddress && {\n remoteAddress,\n }),\n ...info,\n },\n EOL\n );\n};\n"],"file":"logConnected.js"}