not-node 6.5.3 → 6.5.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/package.json +1 -1
- package/src/init/index.js +54 -17
- package/src/init/sequence.js +5 -5
- package/src/metas.js +3 -2
- package/test/notInit.js +2 -0
package/package.json
CHANGED
package/src/init/index.js
CHANGED
|
@@ -13,25 +13,59 @@ const STANDART_INIT_SEQUENCE = require("./sequence.standart.js");
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @example <caption>Application initialization</caption>
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
16
|
+
*
|
|
17
|
+
* const sharp = require("sharp");
|
|
18
|
+
* const InitIdentityTokens = require("not-user").InitIdentityTokens;
|
|
19
|
+
*
|
|
20
|
+
* const notNode = require("not-node"),
|
|
21
|
+
* Init = notNode.Init,
|
|
22
|
+
* path = require("path"),
|
|
23
|
+
* manifest = require("./../../project.manifest.json")
|
|
24
|
+
*
|
|
25
|
+
* const options = {
|
|
26
|
+
* pathToApp: path.join(__dirname),
|
|
27
|
+
* pathToNPM: path.join(__dirname, "../../node_modules"),
|
|
28
|
+
* routesPath: path.join(__dirname, "./routes"),
|
|
29
|
+
* indexRoute: require("./routes/site.js").index,
|
|
30
|
+
* };
|
|
31
|
+
* //fix error on some images
|
|
32
|
+
* sharp.simd(false);
|
|
33
|
+
* notNode.Env.set("extractVariants", 1);
|
|
34
|
+
* const additional = {
|
|
35
|
+
* pre({ initSequence }) {
|
|
36
|
+
* initSequence.remove("InitMonitoring"); //no resource usage monitoring needed, removing initializer by its class name
|
|
37
|
+
* initSequence.insert(InitIdentityTokens); //initializing usage of identity tokens
|
|
38
|
+
* },
|
|
39
|
+
* };
|
|
40
|
+
* //starting everything
|
|
41
|
+
* await Init.run({ options, manifest, additional });
|
|
42
|
+
* //sending message to error reporting server that we restarted
|
|
43
|
+
* Init.notApp.reporter.report(new Error("server started"));
|
|
28
44
|
**/
|
|
29
45
|
class Init {
|
|
30
|
-
|
|
46
|
+
/**
|
|
47
|
+
* @type {Object}
|
|
48
|
+
*
|
|
49
|
+
* @static
|
|
50
|
+
* @memberof Init
|
|
51
|
+
*/
|
|
52
|
+
static options = null;
|
|
31
53
|
static manifest = false;
|
|
32
|
-
|
|
54
|
+
/**
|
|
55
|
+
* @type {Object}
|
|
56
|
+
*
|
|
57
|
+
* @static
|
|
58
|
+
* @memberof Init
|
|
59
|
+
*/
|
|
60
|
+
static config = null;
|
|
33
61
|
static mongoose = false;
|
|
34
|
-
|
|
62
|
+
/**
|
|
63
|
+
* @type {import('../app.js')|null}
|
|
64
|
+
*
|
|
65
|
+
* @static
|
|
66
|
+
* @memberof Init
|
|
67
|
+
*/
|
|
68
|
+
static notApp = null;
|
|
35
69
|
static server = false;
|
|
36
70
|
static httpServer = false;
|
|
37
71
|
static WSServer = false;
|
|
@@ -107,7 +141,7 @@ class Init {
|
|
|
107
141
|
|
|
108
142
|
static printOutManifest = () => {
|
|
109
143
|
log?.debug("Manifest:");
|
|
110
|
-
log?.debug(JSON.stringify(Init.notApp
|
|
144
|
+
log?.debug(JSON.stringify(Init.notApp?.getManifest(), null, 4));
|
|
111
145
|
};
|
|
112
146
|
|
|
113
147
|
/**
|
|
@@ -131,6 +165,7 @@ class Init {
|
|
|
131
165
|
manifest,
|
|
132
166
|
additional,
|
|
133
167
|
initSequence, //giving a chance to change init sequence
|
|
168
|
+
log,
|
|
134
169
|
});
|
|
135
170
|
//setting basic resources
|
|
136
171
|
Init.options = options; // pathToApp, pathToNPM
|
|
@@ -143,6 +178,7 @@ class Init {
|
|
|
143
178
|
options, //options
|
|
144
179
|
master: Init, //this class
|
|
145
180
|
emit: ADDS.run.bind(ADDS),
|
|
181
|
+
log,
|
|
146
182
|
};
|
|
147
183
|
//running all prepared initalizers with current context
|
|
148
184
|
await initSequence.run(context);
|
|
@@ -151,8 +187,9 @@ class Init {
|
|
|
151
187
|
options,
|
|
152
188
|
manifest,
|
|
153
189
|
master: Init,
|
|
190
|
+
log,
|
|
154
191
|
});
|
|
155
|
-
log
|
|
192
|
+
log?.info("Application initalization finished");
|
|
156
193
|
} catch (e) {
|
|
157
194
|
Init.throwError(e.message, 1);
|
|
158
195
|
}
|
package/src/init/sequence.js
CHANGED
|
@@ -13,19 +13,19 @@ module.exports = class InitSequence {
|
|
|
13
13
|
* Insert initalizator after and before specified modules or at the end
|
|
14
14
|
* @param {Object} what initializator class constructor
|
|
15
15
|
* @param {Object} where specification where to insert
|
|
16
|
-
* @param {
|
|
16
|
+
* @param {string} where.after list of constructor names of
|
|
17
17
|
* initalizators after which item should be inserted
|
|
18
|
-
* @param {
|
|
18
|
+
* @param {string} where.before list of constructor names of
|
|
19
19
|
* initalizators before which item should be inserted
|
|
20
20
|
**/
|
|
21
|
-
insert(what, where = {}) {
|
|
21
|
+
insert(what, where = { after: "", before: "" }) {
|
|
22
22
|
if (where && this.list.length > 0) {
|
|
23
23
|
let start = -1,
|
|
24
24
|
end = this.list.length;
|
|
25
|
-
if (objHas(where, "after")) {
|
|
25
|
+
if (objHas(where, "after") && where.after) {
|
|
26
26
|
start = this.highestPos(where.after);
|
|
27
27
|
}
|
|
28
|
-
if (objHas(where, "before")) {
|
|
28
|
+
if (objHas(where, "before") && where.before) {
|
|
29
29
|
end = this.lowestPos(where.before);
|
|
30
30
|
}
|
|
31
31
|
if (start > end) {
|
package/src/metas.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const Auth = require("./auth"),
|
|
2
2
|
notAppIdentity = require("./identity"),
|
|
3
3
|
notStyler = require("./styler"),
|
|
4
|
-
|
|
4
|
+
notEnv = require("./env");
|
|
5
5
|
|
|
6
6
|
function getRole(req) {
|
|
7
7
|
const identity = new notAppIdentity(req);
|
|
@@ -14,7 +14,7 @@ function getRole(req) {
|
|
|
14
14
|
|
|
15
15
|
const DEFAULT_STYLER = (req, res) => {
|
|
16
16
|
const role = getRole(req);
|
|
17
|
-
const host =
|
|
17
|
+
const host = notEnv.get("fullServerName");
|
|
18
18
|
const canonical = host + req.originalUrl;
|
|
19
19
|
|
|
20
20
|
return {
|
|
@@ -22,6 +22,7 @@ const DEFAULT_STYLER = (req, res) => {
|
|
|
22
22
|
desription: res?.options?.APP_DESCRIPTION,
|
|
23
23
|
canonical,
|
|
24
24
|
rand: Math.random(),
|
|
25
|
+
env: process.env.NODE_ENV,
|
|
25
26
|
host,
|
|
26
27
|
role,
|
|
27
28
|
authenticated: role !== Auth.DEFAULT_USER_ROLE_FOR_GUEST,
|
package/test/notInit.js
CHANGED
|
@@ -158,6 +158,7 @@ describe("initialization", function () {
|
|
|
158
158
|
"manifest",
|
|
159
159
|
"additional",
|
|
160
160
|
"initSequence",
|
|
161
|
+
"log",
|
|
161
162
|
]);
|
|
162
163
|
expect(params.config).to.be.deep.equal(config);
|
|
163
164
|
expect(params.options).to.be.deep.equal(options);
|
|
@@ -188,6 +189,7 @@ describe("initialization", function () {
|
|
|
188
189
|
"manifest",
|
|
189
190
|
"additional",
|
|
190
191
|
"initSequence",
|
|
192
|
+
"log",
|
|
191
193
|
]);
|
|
192
194
|
expect(params.config).to.be.deep.equal(config);
|
|
193
195
|
expect(params.options).to.be.deep.equal(options);
|