This repository has been archived by the owner on Nov 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerBootstrap.js
65 lines (56 loc) · 1.67 KB
/
ServerBootstrap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"use strict";
const PRuntime = require("../core/PRuntime");
/**
* Bootstrap elements for server part of the framework.
*
* @memberOf puzzle
* @extends core.PRuntime
*/
class ServerBootstrap extends PRuntime {
/**
* Register process handlers and display some messages in log before
* starting the application.
*/
beforeBoot() {
puzzle.log.info("Application started");
puzzle.log.info("-".repeat(30));
puzzle.log.info(`Puzzle Framework Version: ${puzzle.version.version}`);
puzzle.log.info(`Framework type: ${puzzle.lite ? "Lite" : "Full"}`);
puzzle.log.info(`Environment: ${puzzle.env}`);
puzzle.log.info(`Logging level: ${puzzle.logLevel}`);
puzzle.log.info("-".repeat(30));
// do something when app is closing
process.on("exit", this.close.bind(this, {}));
// catches ctrl+c event
process.on("SIGINT", this.close.bind(this, {
exit: true
}));
// catches uncaught exceptions
process.on("uncaughtException", this.close.bind(this, {
exit: true
}));
}
/**
* Shut downs the server.
*/
shutdown() {
super.shutdown();
if (this.isValid(puzzle.server)) {
puzzle.log.info("Shutting down the HTTP server");
puzzle.server.close();
}
}
/**
* Event called when the application is closed.
*
* @param {Object} options The options sent by the closing event.
* @param {Object} err The errors sent by the closing event.
*/
close(options, err) {
if (err && puzzle && puzzle.log) puzzle.log.error(err);
if (options && options.exit) process.exit();
puzzle.modules.shutdown();
puzzle.log.info("Application closed");
}
}
module.exports = ServerBootstrap;