@adaptivestone/framework 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 3.0.4
2
+
3
+ [UPDATE] fix bug with app shutdown
4
+
1
5
  ### 3.0.3
2
6
 
3
7
  [UPDATE] update deps
package/Cli.js CHANGED
@@ -12,7 +12,7 @@ class Cli extends BaseCli {
12
12
  async run() {
13
13
  const command = process.argv[2]?.toLowerCase();
14
14
  await super.run(command, this.args);
15
- this.app.events.emit('die');
15
+ this.app.events.emit('shutdown');
16
16
  }
17
17
  }
18
18
 
@@ -23,7 +23,7 @@ class AbstractModel extends Base {
23
23
  mongoose.connect(this.app.getConfig('mongo').connectionString, {}).then(
24
24
  () => {
25
25
  this.logger.info('Mongo connection success');
26
- this.app.events.on('die', async () => {
26
+ this.app.events.on('shutdown', async () => {
27
27
  for (const c of mongoose.connections) {
28
28
  c.close(true);
29
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptivestone/framework",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "description": "Adaptive stone node js framework",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -17,6 +17,9 @@ class Cache extends Base {
17
17
  this.redisClient.on('connect', () => {
18
18
  this.logger.info('Redis connection success');
19
19
  });
20
+ this.app.events.on('shutdown', () => {
21
+ this.redisClient.quit();
22
+ });
20
23
  this.redisGetAsync = promisify(this.redisClient.get).bind(this.redisClient);
21
24
  this.promiseMapping = new Map();
22
25
  }
@@ -168,7 +168,7 @@ class HttpServer extends Base {
168
168
  /**
169
169
  * Stop http server (mostly for unit testing)
170
170
  */
171
- die() {
171
+ shutdown() {
172
172
  this.httpServer.close();
173
173
  }
174
174
  }
@@ -55,6 +55,10 @@ class RateLimiter extends AbstractMiddleware {
55
55
  this.logger.info('Redis connection success');
56
56
  });
57
57
 
58
+ this.app.events.on('shutdown', () => {
59
+ redisClient.quit();
60
+ });
61
+
58
62
  return new RateLimiterRedis({
59
63
  storeClient: redisClient,
60
64
  ...this.finalOptions.limiterOptions,
package/tests/setup.js CHANGED
@@ -64,7 +64,8 @@ beforeAll(async () => {
64
64
  });
65
65
  afterAll(async () => {
66
66
  if (global.server) {
67
- global.server.app.httpServer.die();
67
+ global.server.app.httpServer.shutdown();
68
+ global.server.app.events.emit('shutdown');
68
69
  }
69
70
  setTimeout(async () => {
70
71
  if (typeof global.testSetup.afterAll === 'function') {