1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | Object.defineProperty(exports, "__esModule", {
|
5 | value: true
|
6 | });
|
7 | exports["default"] = exports.SampleApp = void 0;
|
8 | var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
9 | var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
10 | var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
11 | var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
12 | var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
13 | var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
14 | var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
15 | var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
16 | var _module = _interopRequireDefault(require("@lskjs/module"));
|
17 | var _env = require("@lskjs/utils/env");
|
18 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
19 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
20 | var SampleApp = function (_Module) {
|
21 | (0, _inherits2["default"])(SampleApp, _Module);
|
22 | var _super = _createSuper(SampleApp);
|
23 | function SampleApp() {
|
24 | var _this;
|
25 | (0, _classCallCheck2["default"])(this, SampleApp);
|
26 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
27 | args[_key] = arguments[_key];
|
28 | }
|
29 | _this = _super.call.apply(_super, [this].concat(args));
|
30 | _this.preload = true;
|
31 | return _this;
|
32 | }
|
33 | (0, _createClass2["default"])(SampleApp, [{
|
34 | key: "init",
|
35 | value: function () {
|
36 | var _init = (0, _asyncToGenerator2["default"])( _regenerator["default"].mark(function _callee() {
|
37 | var _this2 = this;
|
38 | return _regenerator["default"].wrap(function _callee$(_context) {
|
39 | while (1) switch (_context.prev = _context.next) {
|
40 | case 0:
|
41 | _context.next = 2;
|
42 | return (0, _get2["default"])((0, _getPrototypeOf2["default"])(SampleApp.prototype), "init", this).call(this);
|
43 | case 2:
|
44 | this.on('runFinish', function () {
|
45 | return _this2.started();
|
46 | });
|
47 | case 3:
|
48 | case "end":
|
49 | return _context.stop();
|
50 | }
|
51 | }, _callee, this);
|
52 | }));
|
53 | function init() {
|
54 | return _init.apply(this, arguments);
|
55 | }
|
56 | return init;
|
57 | }()
|
58 | }, {
|
59 | key: "run",
|
60 | value: function () {
|
61 | var _run = (0, _asyncToGenerator2["default"])( _regenerator["default"].mark(function _callee2() {
|
62 | return _regenerator["default"].wrap(function _callee2$(_context2) {
|
63 | while (1) switch (_context2.prev = _context2.next) {
|
64 | case 0:
|
65 | _context2.next = 2;
|
66 | return (0, _get2["default"])((0, _getPrototypeOf2["default"])(SampleApp.prototype), "run", this).call(this);
|
67 | case 2:
|
68 | if (!this.preload) {
|
69 | _context2.next = 15;
|
70 | break;
|
71 | }
|
72 | if (!this.hasModule('db')) {
|
73 | _context2.next = 6;
|
74 | break;
|
75 | }
|
76 | _context2.next = 6;
|
77 | return this.module('db');
|
78 | case 6:
|
79 | if (!this.hasModule('esModels')) {
|
80 | _context2.next = 9;
|
81 | break;
|
82 | }
|
83 | _context2.next = 9;
|
84 | return this.module('esModels');
|
85 | case 9:
|
86 | if (!this.hasModule('elastic')) {
|
87 | _context2.next = 12;
|
88 | break;
|
89 | }
|
90 | _context2.next = 12;
|
91 | return this.module('elastic');
|
92 | case 12:
|
93 | if (!this.hasModule('models')) {
|
94 | _context2.next = 15;
|
95 | break;
|
96 | }
|
97 | _context2.next = 15;
|
98 | return this.module('models.*');
|
99 | case 15:
|
100 | case "end":
|
101 | return _context2.stop();
|
102 | }
|
103 | }, _callee2, this);
|
104 | }));
|
105 | function run() {
|
106 | return _run.apply(this, arguments);
|
107 | }
|
108 | return run;
|
109 | }()
|
110 | }, {
|
111 | key: "started",
|
112 | value: function () {
|
113 | var _started = (0, _asyncToGenerator2["default"])( _regenerator["default"].mark(function _callee3() {
|
114 | var timing, rawAddress, webserver, str, _rawAddress, port, address;
|
115 | return _regenerator["default"].wrap(function _callee3$(_context3) {
|
116 | while (1) switch (_context3.prev = _context3.next) {
|
117 | case 0:
|
118 | timing = global.timing ? "[".concat(global.timing(), "ms]") : '';
|
119 | if (!(this.hasModule('webserver') && this.__initedModules.webserver)) {
|
120 | _context3.next = 6;
|
121 | break;
|
122 | }
|
123 | _context3.next = 4;
|
124 | return this.module('webserver');
|
125 | case 4:
|
126 | webserver = _context3.sent;
|
127 | rawAddress = webserver.httpInstance.address();
|
128 | case 6:
|
129 | if (rawAddress) {
|
130 | _rawAddress = rawAddress, port = _rawAddress.port, address = _rawAddress.address;
|
131 | str = "\uD83D\uDE80 The ".concat(this.name, " is [ready] at http://").concat(address === '::' ? '127.0.0.1' : address, ":").concat(port, "/ ").concat(timing);
|
132 | } else {
|
133 | str = "\uD83D\uDE80 The ".concat(this.name, " is [ready] ").concat(timing);
|
134 | }
|
135 | if (_env.isDev) {
|
136 | this.log.info(str);
|
137 | } else {
|
138 | this.log.warn(str);
|
139 | }
|
140 | case 8:
|
141 | case "end":
|
142 | return _context3.stop();
|
143 | }
|
144 | }, _callee3, this);
|
145 | }));
|
146 | function started() {
|
147 | return _started.apply(this, arguments);
|
148 | }
|
149 | return started;
|
150 | }()
|
151 | }, {
|
152 | key: "healthchecks",
|
153 | value: function healthchecks() {
|
154 | var _this3 = this;
|
155 | var healthchecks = {};
|
156 | Object.keys(this.__initedModules).forEach(function (moduleName) {
|
157 | healthchecks[moduleName] = (0, _asyncToGenerator2["default"])( _regenerator["default"].mark(function _callee4() {
|
158 | var m;
|
159 | return _regenerator["default"].wrap(function _callee4$(_context4) {
|
160 | while (1) switch (_context4.prev = _context4.next) {
|
161 | case 0:
|
162 | _context4.next = 2;
|
163 | return _this3.module(moduleName);
|
164 | case 2:
|
165 | m = _context4.sent;
|
166 | if (m.healthcheck) {
|
167 | _context4.next = 5;
|
168 | break;
|
169 | }
|
170 | return _context4.abrupt("return", null);
|
171 | case 5:
|
172 | return _context4.abrupt("return", m.healthcheck());
|
173 | case 6:
|
174 | case "end":
|
175 | return _context4.stop();
|
176 | }
|
177 | }, _callee4);
|
178 | }));
|
179 | });
|
180 | return healthchecks;
|
181 | }
|
182 | }]);
|
183 | return SampleApp;
|
184 | }(_module["default"]);
|
185 | exports.SampleApp = SampleApp;
|
186 | var _default = SampleApp;
|
187 | exports["default"] = _default;
|
188 |
|
\ | No newline at end of file |