Skip to content

Commit 935e2f8

Browse files
fix: add remove cookie options
1 parent 190511e commit 935e2f8

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

__tests__/services/abstract-microservice-test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import BaseException from '@core/base-exception';
88
import MicroserviceRequest from '@core/microservice-request';
99
import MicroserviceResponse from '@core/microservice-response';
1010
import ConsoleLog from '@drivers/console-log';
11-
import { MiddlewareHandler, MiddlewareType } from '@interfaces/services/i-abstract-microservice';
11+
import type { MiddlewareHandler } from '@interfaces/services/i-abstract-microservice';
12+
import { MiddlewareType } from '@interfaces/services/i-abstract-microservice';
1213
import AbstractMicroservice from '@services/abstract-microservice';
1314
import Microservice from '@services/microservice';
1415

__tests__/services/gateway-test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import { Server } from 'http';
1+
import type { Server } from 'http';
22
import axios from 'axios';
33
import { expect } from 'chai';
4-
import { Response } from 'express';
4+
import type { Response } from 'express';
55
import _ from 'lodash';
66
import type { SinonStub } from 'sinon';
77
import sinon from 'sinon';
88
import { EXCEPTION_CODE } from '@constants/index';
99
import MicroserviceResponse from '@core/microservice-response';
1010
import { CookiesAction } from '@interfaces/core/i-microservice-response';
11-
import { MiddlewareHandler, MiddlewareType } from '@interfaces/services/i-abstract-microservice';
12-
import { IExpressRequest } from '@interfaces/services/i-gateway';
11+
import type { MiddlewareHandler } from '@interfaces/services/i-abstract-microservice';
12+
import { MiddlewareType } from '@interfaces/services/i-abstract-microservice';
13+
import type { IExpressRequest } from '@interfaces/services/i-gateway';
1314
import AbstractMicroservice from '@services/abstract-microservice';
1415
import Gateway from '@services/gateway';
1516

@@ -407,7 +408,7 @@ describe('services/gateway', () => {
407408
value: 'test1',
408409
options: { httpOnly: true },
409410
},
410-
{ action: CookiesAction.remove, name: 'cookie2' },
411+
{ action: CookiesAction.remove, name: 'cookie2', options: { domain: 'test' } },
411412
],
412413
},
413414
},
@@ -423,7 +424,12 @@ describe('services/gateway', () => {
423424
const result = res.json.firstCall.firstArg;
424425

425426
expect(addCookie).to.deep.equal(['cookie1', 'test1', { httpOnly: true }]);
426-
expect(clearCookie).to.deep.equal(['cookie2']);
427+
expect(clearCookie).to.deep.equal([
428+
'cookie2',
429+
{
430+
domain: 'test',
431+
},
432+
]);
427433
expect(result.payload).to.undefined;
428434
});
429435
});

src/services/abstract-microservice.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ abstract class AbstractMicroservice {
369369
} catch (e) {
370370
// Could not connect to ijson or channel
371371
if (e.message === 'socket hang up' || e.message.includes('ECONNREFUSED')) {
372+
this.logDriver(() => `Worker shutdown: ${e.message as string}`, LogType.ERROR);
373+
372374
throw e;
373375
}
374376

src/services/gateway.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,14 @@ class Gateway extends AbstractMicroservice {
253253
_.unset(reqPayload, 'cookies');
254254

255255
cookies.forEach((cookie) => {
256-
switch (cookie.action) {
256+
const { action, name, value, options } = cookie;
257+
258+
switch (action) {
257259
case 'add':
258-
res.cookie(cookie.name, cookie.value, cookie.options ?? {});
260+
res.cookie(name, value, options ?? {});
259261
break;
260262
case 'remove':
261-
res.clearCookie(cookie.name);
263+
res.clearCookie(name, options ?? {});
262264
}
263265
});
264266
}

0 commit comments

Comments
 (0)