diff --git a/src/app.controller.ts b/src/app.controller.ts index 65b5eb0..828c10c 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -13,4 +13,11 @@ export class AppController { getHello(): string { return 'Hello World!'; } + + @Get('/test') + test() { + // console.log(req.headers.cookie); + console.log('test'); + return 'test'; + } } diff --git a/src/auth/provider/common.auth.service.ts b/src/auth/provider/common.auth.service.ts index 165ae1b..8f578d9 100644 --- a/src/auth/provider/common.auth.service.ts +++ b/src/auth/provider/common.auth.service.ts @@ -13,12 +13,8 @@ export class AuthService { private readonly jwtOption: JwtOption, ) {} - cookieVerify(cookie: string): ErAuth.AccessTokenSignPayload | EmsAuth.AccessTokenSignPayload { - const access_token = cookie - .split(';') - .filter((v) => v.includes('access_token'))[0] - .split('=')[1]; - return this.accessTokenVerify({ access_token }); + tokenVerify(token: string): ErAuth.AccessTokenSignPayload | EmsAuth.AccessTokenSignPayload { + return this.accessTokenVerify({ access_token: token }); } accessTokenVerify({ access_token, diff --git a/src/consumers/req.consumer.ts b/src/consumers/req.consumer.ts index f0992ba..98741c9 100644 --- a/src/consumers/req.consumer.ts +++ b/src/consumers/req.consumer.ts @@ -25,8 +25,9 @@ export class ReqConsumer { if (diffMinutes > 5) { return; } - console.log(payload); + // console.log(payload); this.reqGateway.notifyEmsToErNewRequestToEr(payload); + this.reqGateway.notifyEmsToErNewRequestToErForEms(payload); } /** @@ -36,6 +37,7 @@ export class ReqConsumer { */ @MessagePattern(EMS_REQUEST_ER_RESPONSE) async handleEmsToErResponse(@Payload() payload: EmsToErRequestMessage.EmsToErRes) { + console.log(payload); this.reqGateway.notifyEmsToErReqResponseToEms(payload); } diff --git a/src/gateways/req.gateway.ts b/src/gateways/req.gateway.ts index 218fc90..1655ba5 100644 --- a/src/gateways/req.gateway.ts +++ b/src/gateways/req.gateway.ts @@ -30,25 +30,27 @@ export class ReqGateway implements OnGatewayConnection, OnGatewayDisconnect, OnG } async handleConnection(client: Socket) { - const cookies = client.handshake.headers.cookie; - if (!cookies) { + const token: string = client.handshake.auth.token; + if (!token) { client.disconnect(); return; } - const isValidCookie = this.authService.cookieVerify(cookies); - if (!isValidCookie) { + + const isValidToken = this.authService.tokenVerify(token); + if (!isValidToken) { client.disconnect(); return; } - const { type } = isValidCookie; + console.log(isValidToken); + const { type } = isValidToken; if (type === 'ems') { - const { ambulance_company_id, employee_id } = isValidCookie; + const { ambulance_company_id, employee_id } = isValidToken; await client.join(`request-ems-${ambulance_company_id}-${employee_id}`); this.logger.debug(`ems request-${client.id} is connected! ${ambulance_company_id}:${employee_id}`); } if (type === 'er') { - const { emergency_center_id, employee_id } = isValidCookie; + const { emergency_center_id, employee_id } = isValidToken; await client.join(`request-er-${emergency_center_id}`); this.logger.debug(`er request-${client.id} is connected! ${emergency_center_id}:${employee_id}`); } @@ -62,7 +64,11 @@ export class ReqGateway implements OnGatewayConnection, OnGatewayDisconnect, OnG notifyEmsToErNewRequestToEr(payload: EmsToErRequestMessage.EmsToErReq) { this.server.to(`request-er-${payload.emergency_center_id}`).emit(EMS_REQUEST_ER, payload); } - + notifyEmsToErNewRequestToErForEms(payload: EmsToErRequestMessage.EmsToErReq) { + const { patient } = payload; + const { ambulance_company_id, ems_employee_id } = patient; + this.server.to(`request-ems-${ambulance_company_id}-${ems_employee_id}`).emit(EMS_REQUEST_ER, payload); + } notifyEmsToErReqResponseToEms(payload: EmsToErRequestMessage.EmsToErRes) { this.server .to(`request-ems-${payload.ambulance_company_id}-${payload.ems_employee_id}`) diff --git a/src/main.ts b/src/main.ts index 32fe27b..edd10d3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -26,8 +26,17 @@ async function bootstrap() { app.setGlobalPrefix('api'); app.enableCors({ - origin: '*', + origin: [ + 'https://er.ho-it.me', + 'https://ems.ho-it.me', + 'http://er.development.com', + 'http://ems.development.com', + 'http://localhost:4000', + 'http://localhost:3000', + ], + credentials: true, }); + await app.startAllMicroservices(); await app.listen(port);