spec-3nweb-server 1.6.3 → 1.7.0
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/README.md +0 -1
- package/build/3nstorage/3nstorage-app.d.ts +2 -1
- package/build/3nstorage/3nstorage-app.js +2 -7
- package/build/admin/admin-app.d.ts +2 -1
- package/build/admin/admin-app.js +5 -2
- package/build/asmail/asmail-app.d.ts +2 -1
- package/build/asmail/asmail-app.js +2 -7
- package/build/config/cli/index.d.ts +9 -0
- package/build/config/cli/index.js +68 -0
- package/build/config/cli/run-cmd.d.ts +10 -0
- package/build/config/cli/run-cmd.js +69 -0
- package/build/config/cli/signup-cmd.d.ts +17 -0
- package/build/config/cli/signup-cmd.js +194 -0
- package/build/config/cli/user-cmd.d.ts +9 -0
- package/build/config/cli/user-cmd.js +55 -0
- package/build/config/cli/utils.d.ts +45 -0
- package/build/config/cli/utils.js +52 -0
- package/build/{run-config.d.ts → config/from-env.d.ts} +1 -2
- package/build/{run-config.js → config/from-env.js} +2 -31
- package/build/config/from-yaml.d.ts +2 -0
- package/build/config/from-yaml.js +28 -0
- package/build/config/letsencrypt.d.ts +7 -0
- package/build/config/letsencrypt.js +62 -0
- package/build/config/signup.d.ts +15 -0
- package/build/config/signup.js +132 -0
- package/build/lib-server/middleware/error-handler.d.ts +1 -0
- package/build/lib-server/middleware/error-handler.js +11 -2
- package/build/lib-server/resources/dns.js +48 -10
- package/build/lib.d.ts +6 -4
- package/build/lib.js +13 -4
- package/build/mailerId/mailerId-app.d.ts +2 -1
- package/build/mailerId/mailerId-app.js +2 -2
- package/build/main.js +199 -48
- package/build/mock/run-in-proc.js +6 -3
- package/build/run.js +19 -9
- package/build/services.d.ts +5 -2
- package/build/services.js +19 -6
- package/package.json +15 -2
- package/postinstall.js +25 -0
package/build/main.js
CHANGED
|
@@ -13,70 +13,221 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const async_fs_node_1 = require("./lib-common/async-fs-node");
|
|
25
|
-
const child_process_1 = require("child_process");
|
|
26
|
-
const processes_1 = require("./lib-common/processes");
|
|
27
|
-
const PID_FILE = '/var/3nweb/service.pid';
|
|
28
|
-
const confFile = process.argv[2];
|
|
29
|
-
if (!confFile) {
|
|
30
|
-
console.error(`Configuration file is not given. It should be the first script argument.`);
|
|
31
|
-
process.exit(-1);
|
|
32
|
-
}
|
|
33
|
-
const conf = JSON.parse((0, fs_1.readFileSync)(confFile, 'utf8'));
|
|
34
|
-
const noop = () => { };
|
|
35
|
-
(async () => {
|
|
19
|
+
const cli_1 = require("./config/cli");
|
|
20
|
+
const from_yaml_1 = require("./config/from-yaml");
|
|
21
|
+
const letsencrypt_1 = require("./config/letsencrypt");
|
|
22
|
+
const lib_1 = require("./lib");
|
|
23
|
+
const signup_1 = require("./config/signup");
|
|
24
|
+
async function run(conf) {
|
|
36
25
|
if (!conf.servicesConnect) {
|
|
37
|
-
console.error(`No connection settings found in
|
|
26
|
+
console.error(`No connection settings found in ??.`);
|
|
38
27
|
process.exit(-1);
|
|
39
28
|
return;
|
|
40
29
|
}
|
|
41
|
-
try {
|
|
42
|
-
const prevPidStr = await (0, async_fs_node_1.readFile)(PID_FILE, { encoding: 'utf8' });
|
|
43
|
-
const prevPid = Number.parseInt(prevPidStr);
|
|
44
|
-
if (!Number.isNaN(prevPid)) {
|
|
45
|
-
(0, child_process_1.execSync)(`kill -SIGTERM ${prevPid}`);
|
|
46
|
-
while (!!(0, child_process_1.execSync)(`ps ${prevPid} | grep ${prevPid}`)) {
|
|
47
|
-
await (0, processes_1.sleep)(1000);
|
|
48
|
-
}
|
|
49
|
-
await (0, async_fs_node_1.unlink)(PID_FILE).catch(noop);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch (err) {
|
|
53
|
-
if (!err.notFound) {
|
|
54
|
-
throw err;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
30
|
let app = undefined;
|
|
31
|
+
function createApp(conf) {
|
|
32
|
+
const app = new lib_1.AppWithWSs();
|
|
33
|
+
app.use((0, lib_1.servicesApp)(conf, 'console', 'console'));
|
|
34
|
+
app.use((0, lib_1.adminApp)(conf, 'console', 'console'));
|
|
35
|
+
return app;
|
|
36
|
+
}
|
|
58
37
|
async function stopProcess() {
|
|
59
38
|
if (!app) {
|
|
60
39
|
return;
|
|
61
40
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
41
|
+
try {
|
|
42
|
+
console.log(`Stopping app ...`);
|
|
43
|
+
await app.stop();
|
|
44
|
+
console.log(`app has stopped.`);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
console.log(`app encounter an error, when stopping`);
|
|
48
|
+
console.error(err);
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
app = undefined;
|
|
52
|
+
}
|
|
65
53
|
}
|
|
66
|
-
|
|
67
|
-
app = new app_1.AppWithWSs();
|
|
68
|
-
app.use((0, services_1.servicesApp)(conf));
|
|
69
|
-
app.use((0, services_1.adminApp)(conf));
|
|
70
|
-
const { hostname, port, sslOpts } = conf.servicesConnect;
|
|
54
|
+
async function startAppWithTLS(sslOpts, port, hostname) {
|
|
71
55
|
await app.start(sslOpts, port, hostname);
|
|
72
|
-
console.log(`Started 3NWeb server
|
|
73
|
-
|
|
56
|
+
console.log(`Started 3NWeb server on port ${port},${hostname ? ` hostname ${hostname},` : ''} with TLS.`);
|
|
57
|
+
}
|
|
58
|
+
async function startAppWithoutTLS(port, hostname) {
|
|
59
|
+
await app.start(undefined, port, hostname);
|
|
60
|
+
console.log(`Started 3NWeb server on port ${port},${hostname ? ` hostname ${hostname},` : ''} without TLS, and requiring TLS reverse proxy infront.`);
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
app = createApp(conf);
|
|
64
|
+
const { hostname, port, letsencrypt, sslOpts, skipReloadOnCertsChange } = conf.servicesConnect;
|
|
65
|
+
const tls = (0, letsencrypt_1.sslOptsFromConfig)(letsencrypt, sslOpts, skipReloadOnCertsChange);
|
|
66
|
+
if (tls) {
|
|
67
|
+
await startAppWithTLS(tls.sslOpts, port, hostname);
|
|
68
|
+
if (!skipReloadOnCertsChange) {
|
|
69
|
+
tls.onCertsUpdate(async (newOpts, originalOpts) => {
|
|
70
|
+
console.log(`Reloading server app server on TLS certificates change`);
|
|
71
|
+
try {
|
|
72
|
+
await stopProcess();
|
|
73
|
+
app = createApp(conf);
|
|
74
|
+
await startAppWithTLS(newOpts, port, hostname);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.error(err);
|
|
78
|
+
console.log(`Failed to reload with new TLS certs. Attempting to load with original ones.`);
|
|
79
|
+
try {
|
|
80
|
+
await stopProcess();
|
|
81
|
+
app = createApp(conf);
|
|
82
|
+
await startAppWithTLS(originalOpts, port, hostname);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
await stopProcess();
|
|
86
|
+
console.error(err);
|
|
87
|
+
process.exit(-500);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
await startAppWithoutTLS(port, hostname);
|
|
95
|
+
}
|
|
74
96
|
process.on('SIGINT', stopProcess);
|
|
75
97
|
process.on('SIGTERM', stopProcess);
|
|
76
98
|
}
|
|
77
99
|
catch (err) {
|
|
78
|
-
stopProcess();
|
|
100
|
+
await stopProcess();
|
|
79
101
|
console.error(err);
|
|
80
102
|
process.exit(-500);
|
|
81
103
|
}
|
|
82
|
-
}
|
|
104
|
+
}
|
|
105
|
+
function showUsage({ txtToDisplay, exitStatus }) {
|
|
106
|
+
if (exitStatus === 0) {
|
|
107
|
+
console.log(txtToDisplay);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
console.error(txtToDisplay);
|
|
111
|
+
}
|
|
112
|
+
process.exit(exitStatus);
|
|
113
|
+
}
|
|
114
|
+
function assembleConfig(configPath) {
|
|
115
|
+
if (configPath) {
|
|
116
|
+
return (0, from_yaml_1.readYamlConfFile)(configPath);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
throw new Error(`Config path must be given`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function displaySignupInfo(conf) {
|
|
123
|
+
if (!conf.signup) {
|
|
124
|
+
console.log(`\nSignup is disabled.\n`);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
console.log(`\nSignup is enabled.\n`);
|
|
128
|
+
if (conf.signup.noTokenFile) {
|
|
129
|
+
const ctx = await (0, signup_1.readNoTokensFile)(conf.signup.noTokenFile);
|
|
130
|
+
console.log(`Signup of user without token is allowed in domains:\n`, ctx.domains, `\n`);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
console.log(`Signup of users is allowed only with valid signup tokens.\n`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const { multiUserTokens, singleUserTokens } = await (0, signup_1.readAllSignupTokens)(conf.rootFolder);
|
|
137
|
+
console.log(`There are ${multiUserTokens.length} multi-user tokens.\n`);
|
|
138
|
+
console.log(`There are ${singleUserTokens.length} single-user tokens.\n`);
|
|
139
|
+
}
|
|
140
|
+
async function displayTokensList(conf) {
|
|
141
|
+
const { multiUserTokens, singleUserTokens } = await (0, signup_1.readAllSignupTokens)(conf.rootFolder);
|
|
142
|
+
if (multiUserTokens.length > 0) {
|
|
143
|
+
console.log(`\nMulti-user signup tokens:`);
|
|
144
|
+
for (const { tokenId, ctx: { domains } } of multiUserTokens) {
|
|
145
|
+
console.log(` id: ${tokenId} -> domains:`, domains);
|
|
146
|
+
}
|
|
147
|
+
console.log(``);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
console.log(`\nThere are no multi-user signup tokens.\n`);
|
|
151
|
+
}
|
|
152
|
+
if (singleUserTokens.length > 0) {
|
|
153
|
+
console.log(`Single-user signup tokens:`);
|
|
154
|
+
for (const { tokenId, ctx: { userId } } of singleUserTokens) {
|
|
155
|
+
console.log(` id: ${tokenId} -> user: ${userId}`);
|
|
156
|
+
}
|
|
157
|
+
console.log(``);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
console.log(`There are no single-user signup tokens.\n`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async function displayTokenValue(conf, tokenId) {
|
|
164
|
+
const ctx = await (0, signup_1.readTokenFile)(conf.rootFolder, tokenId);
|
|
165
|
+
if (!ctx) {
|
|
166
|
+
console.error(`Token ${tokenId} is not found.`);
|
|
167
|
+
process.exit(-1);
|
|
168
|
+
}
|
|
169
|
+
else if (ctx.type === 'multi-domain') {
|
|
170
|
+
console.log(`\nMulti-user signup context:`);
|
|
171
|
+
console.log(` domains:`, ctx.domains);
|
|
172
|
+
console.log(` value:`, ctx.token);
|
|
173
|
+
if (ctx.validTill) {
|
|
174
|
+
console.log(` valid till: ${(new Date(ctx.validTill)).toString()}\n`);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
console.log(``);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else if (ctx.type === 'single-user') {
|
|
181
|
+
console.log(`\nSingle-user signup context:`);
|
|
182
|
+
console.log(` address:`, ctx.userId);
|
|
183
|
+
console.log(` value:`, ctx.token);
|
|
184
|
+
if (ctx.validTill) {
|
|
185
|
+
console.log(` valid till: ${(new Date(ctx.validTill)).toString()}\n`);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
console.log(``);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async function createMultiUserToken(conf, domains) {
|
|
193
|
+
const token = await (0, signup_1.addMultiDomainSignup)(conf.rootFolder, domains);
|
|
194
|
+
console.log(`\nToken value:\n ${token}\n`);
|
|
195
|
+
}
|
|
196
|
+
async function createSingleUserToken(conf, userId) {
|
|
197
|
+
const token = await (0, signup_1.addSingleUserSignup)(conf.rootFolder, userId);
|
|
198
|
+
console.log(`\nToken value:\n ${token}\n`);
|
|
199
|
+
}
|
|
200
|
+
const cmd = (0, cli_1.parseProcessArgv)();
|
|
201
|
+
if (cmd.runCmd) {
|
|
202
|
+
const conf = assembleConfig(cmd.runCmd.config);
|
|
203
|
+
run(conf);
|
|
204
|
+
}
|
|
205
|
+
else if (cmd.signupCmd) {
|
|
206
|
+
const conf = assembleConfig(cmd.signupCmd.config);
|
|
207
|
+
if (cmd.signupCmd.info) {
|
|
208
|
+
displaySignupInfo(conf);
|
|
209
|
+
}
|
|
210
|
+
else if (cmd.signupCmd.listTokens) {
|
|
211
|
+
displayTokensList(conf);
|
|
212
|
+
}
|
|
213
|
+
else if (cmd.signupCmd.showToken) {
|
|
214
|
+
displayTokenValue(conf, cmd.signupCmd.token);
|
|
215
|
+
}
|
|
216
|
+
else if (cmd.signupCmd.createToken) {
|
|
217
|
+
if (cmd.signupCmd.user) {
|
|
218
|
+
createSingleUserToken(conf, cmd.signupCmd.user);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
createMultiUserToken(conf, cmd.signupCmd.domain);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
throw new Error(`CLI parser failed to capture invalid command`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
else if (cmd.showUsage) {
|
|
229
|
+
showUsage(cmd.showUsage);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
throw new Error(`CLI parser failed to trigger useful action`);
|
|
233
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2020, 2023 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -37,8 +37,11 @@ function setTestCertsAndDNS(domains, thisSrvLoc) {
|
|
|
37
37
|
for (const domain of domains) {
|
|
38
38
|
dnsRecs[domain] = [
|
|
39
39
|
['asmail', '=', `${thisSrvLoc}/asmail`],
|
|
40
|
-
[
|
|
41
|
-
|
|
40
|
+
[
|
|
41
|
+
'mailerid=', `${thisSrvLoc}/mailerid`,
|
|
42
|
+
`3nstorage=${thisSrvLoc}/3nstorage`
|
|
43
|
+
] // two 3NWeb records in one DNS TXT record
|
|
44
|
+
// XXX add other life-like records
|
|
42
45
|
];
|
|
43
46
|
}
|
|
44
47
|
const dnsMock = new dns_1.DNSMock(dnsRecs);
|
package/build/run.js
CHANGED
|
@@ -13,22 +13,32 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
const
|
|
19
|
-
const app_1 = require("./lib-server/web-sockets/app");
|
|
20
|
-
const run_config_1 = require("./run-config");
|
|
19
|
+
const lib_1 = require("./lib");
|
|
21
20
|
(async () => {
|
|
21
|
+
let app = undefined;
|
|
22
|
+
async function stopProcess() {
|
|
23
|
+
if (!app) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
app.stop().then(err => console.log(err));
|
|
27
|
+
app = undefined;
|
|
28
|
+
}
|
|
22
29
|
try {
|
|
23
|
-
const conf = (0,
|
|
24
|
-
|
|
25
|
-
app.use((0,
|
|
26
|
-
app.use((0,
|
|
27
|
-
const { address, port, sslOpts } = (0,
|
|
30
|
+
const conf = (0, lib_1.getConfsFromEnv)();
|
|
31
|
+
app = new lib_1.AppWithWSs();
|
|
32
|
+
app.use((0, lib_1.servicesApp)(conf));
|
|
33
|
+
app.use((0, lib_1.adminApp)(conf));
|
|
34
|
+
const { address, port, sslOpts } = (0, lib_1.getBindParamsFromEnv)();
|
|
28
35
|
await app.start(sslOpts, port, address);
|
|
29
36
|
console.log(`Started 3NWeb server at address ${address}, port ${port}, ${sslOpts ? 'via TLS' : 'without TLS, and requiring TLS reverse proxy infront.'}`);
|
|
37
|
+
process.on('SIGINT', stopProcess);
|
|
38
|
+
process.on('SIGTERM', stopProcess);
|
|
30
39
|
}
|
|
31
40
|
catch (err) {
|
|
41
|
+
stopProcess();
|
|
32
42
|
console.error(err);
|
|
33
43
|
process.exit(-500);
|
|
34
44
|
}
|
package/build/services.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as https from "https";
|
|
3
3
|
import { AppWithWSs } from './lib-server/web-sockets/app';
|
|
4
|
+
import { ErrLogger } from "./lib-server/middleware/error-handler";
|
|
4
5
|
export interface Configurations {
|
|
5
6
|
enabledServices: {
|
|
6
7
|
asmail?: boolean;
|
|
@@ -11,6 +12,8 @@ export interface Configurations {
|
|
|
11
12
|
hostname?: string;
|
|
12
13
|
port: number;
|
|
13
14
|
sslOpts?: https.ServerOptions;
|
|
15
|
+
letsencrypt?: string;
|
|
16
|
+
skipReloadOnCertsChange?: boolean;
|
|
14
17
|
};
|
|
15
18
|
rootFolder: string;
|
|
16
19
|
domain: string;
|
|
@@ -21,5 +24,5 @@ export interface Configurations {
|
|
|
21
24
|
noTokenFile?: string;
|
|
22
25
|
};
|
|
23
26
|
}
|
|
24
|
-
export declare function servicesApp(conf: Configurations): AppWithWSs;
|
|
25
|
-
export declare function adminApp(conf: Configurations): AppWithWSs;
|
|
27
|
+
export declare function servicesApp(conf: Configurations, errLogger?: ErrLogger | 'console', logSetup?: 'console'): AppWithWSs;
|
|
28
|
+
export declare function adminApp(conf: Configurations, errLogger?: ErrLogger | 'console', logSetup?: 'console'): AppWithWSs;
|
package/build/services.js
CHANGED
|
@@ -23,26 +23,39 @@ const mailerId_app_1 = require("./mailerId/mailerId-app");
|
|
|
23
23
|
const asmail_app_1 = require("./asmail/asmail-app");
|
|
24
24
|
const _3nstorage_app_1 = require("./3nstorage/3nstorage-app");
|
|
25
25
|
const admin_app_1 = require("./admin/admin-app");
|
|
26
|
-
|
|
26
|
+
const error_handler_1 = require("./lib-server/middleware/error-handler");
|
|
27
|
+
function servicesApp(conf, errLogger, logSetup) {
|
|
27
28
|
if (!conf.enabledServices || (typeof conf.enabledServices !== 'object')) {
|
|
28
29
|
throw new Error('Missing enabled-services sections in confs.');
|
|
29
30
|
}
|
|
30
31
|
const app = new app_1.AppWithWSs();
|
|
31
32
|
const midAuthorizer = (0, mailerid_authorizer_1.validator)(); // share, allowing for caching of certs
|
|
32
33
|
if (conf.enabledServices.mailerId) {
|
|
33
|
-
app.http.use('/mailerid', (0, mailerId_app_1.makeApp)(conf.rootFolder, conf.domain, conf.mailerId.certs));
|
|
34
|
+
app.http.use('/mailerid', (0, mailerId_app_1.makeApp)(conf.rootFolder, conf.domain, conf.mailerId.certs, (errLogger === 'console') ? (0, error_handler_1.makeErrLoggerToConsole)('MailerId') : errLogger));
|
|
35
|
+
if (logSetup === 'console') {
|
|
36
|
+
console.log(`Enabled MailerId service with provider domain ${conf.domain}`);
|
|
37
|
+
}
|
|
34
38
|
}
|
|
35
39
|
if (conf.enabledServices.asmail) {
|
|
36
|
-
app.use('/asmail', (0, asmail_app_1.makeApp)(conf.rootFolder, conf.domain, midAuthorizer));
|
|
40
|
+
app.use('/asmail', (0, asmail_app_1.makeApp)(conf.rootFolder, conf.domain, midAuthorizer, (errLogger === 'console') ? (0, error_handler_1.makeErrLoggerToConsole)('ASMail') : errLogger));
|
|
41
|
+
if (logSetup === 'console') {
|
|
42
|
+
console.log(`Enabled ASMail service with provider domain ${conf.domain}`);
|
|
43
|
+
}
|
|
37
44
|
}
|
|
38
45
|
if (conf.enabledServices.storage) {
|
|
39
|
-
app.use('/3nstorage', (0, _3nstorage_app_1.makeApp)(conf.rootFolder, conf.domain, midAuthorizer));
|
|
46
|
+
app.use('/3nstorage', (0, _3nstorage_app_1.makeApp)(conf.rootFolder, conf.domain, midAuthorizer, (errLogger === 'console') ? (0, error_handler_1.makeErrLoggerToConsole)('3NStorage') : errLogger));
|
|
47
|
+
if (logSetup === 'console') {
|
|
48
|
+
console.log(`Enabled 3NStorage service with provider domain ${conf.domain}`);
|
|
49
|
+
}
|
|
40
50
|
}
|
|
41
51
|
return app;
|
|
42
52
|
}
|
|
43
53
|
exports.servicesApp = servicesApp;
|
|
44
|
-
function adminApp(conf) {
|
|
45
|
-
|
|
54
|
+
function adminApp(conf, errLogger, logSetup) {
|
|
55
|
+
if (errLogger === 'console') {
|
|
56
|
+
errLogger = (0, error_handler_1.makeErrLoggerToConsole)('3NWeb server admin');
|
|
57
|
+
}
|
|
58
|
+
return new app_1.AppWithWSs((0, admin_app_1.makeApp)(conf, errLogger, logSetup));
|
|
46
59
|
}
|
|
47
60
|
exports.adminApp = adminApp;
|
|
48
61
|
Object.freeze(exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spec-3nweb-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "3NWeb spec server.",
|
|
5
5
|
"main": "build/lib.js",
|
|
6
6
|
"types": "build/lib.d.ts",
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"test": "node build/tests/jasmine.js",
|
|
10
10
|
"clear-for-packing": "npm prune --production && bash -c \"rm -rf build/mock build/tests 'node_modules/ecma-nacl/c sources'\"",
|
|
11
11
|
"clear-for-packing-mock": "npm prune --production && bash -c \"rm -rf build/tests 'node_modules/ecma-nacl/c sources'\"",
|
|
12
|
-
"pack
|
|
12
|
+
"pack": "pkg --config package.json build/main.js",
|
|
13
|
+
"pack-deb": "npm run pack && bash packing/deb/create-bin.sh",
|
|
14
|
+
"postinstall": "node -e \"try{require('./postinstall')}catch(e){}\""
|
|
13
15
|
},
|
|
14
16
|
"repository": {
|
|
15
17
|
"type": "git",
|
|
@@ -29,8 +31,12 @@
|
|
|
29
31
|
},
|
|
30
32
|
"license": "GPL-3.0",
|
|
31
33
|
"dependencies": {
|
|
34
|
+
"command-line-args": "^5.2.1",
|
|
35
|
+
"command-line-usage": "^7.0.1",
|
|
32
36
|
"ecma-nacl": "^2.4.0",
|
|
33
37
|
"express": "^4.18.0",
|
|
38
|
+
"js-yaml": "^4.1.0",
|
|
39
|
+
"prompts": "^2.4.2",
|
|
34
40
|
"punycode": "^2.1.1",
|
|
35
41
|
"ws": "^7.4.6",
|
|
36
42
|
"xsp-files": "^2.0.0"
|
|
@@ -41,9 +47,16 @@
|
|
|
41
47
|
"@types/node": "^16.11.7",
|
|
42
48
|
"@types/ws": "^4.0.0",
|
|
43
49
|
"jasmine": "^3.9.0",
|
|
50
|
+
"pkg": "^5.8.1",
|
|
44
51
|
"rxjs": "^5.3.0",
|
|
45
52
|
"typescript": "^4.7.4",
|
|
46
53
|
"xhr2": "^0.1.3"
|
|
47
54
|
},
|
|
55
|
+
"pkg": {
|
|
56
|
+
"targets": [
|
|
57
|
+
"node18-linux-x64"
|
|
58
|
+
],
|
|
59
|
+
"outputPath": "dist"
|
|
60
|
+
},
|
|
48
61
|
"readmeFilename": "README.md"
|
|
49
62
|
}
|
package/postinstall.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
function is(it) {
|
|
3
|
+
return !!it && it !== '0' && it !== 'false';
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const env = process.env;
|
|
7
|
+
|
|
8
|
+
const ADBLOCK = is(env.ADBLOCK);
|
|
9
|
+
const SILENT = ['silent', 'error', 'warn'].includes(env.npm_config_loglevel) ;
|
|
10
|
+
const COLOR = is(env.npm_config_color);
|
|
11
|
+
|
|
12
|
+
const BANNER = `\u001B[96mThank you for using spec-server (\u001B[94m https://github.com/3nsoft/spec-server.git \u001B[96m) of 3NWeb uitlity services. This server is developed together with defining 3NWeb protocols by PrivacySafe\u001B[0m
|
|
13
|
+
|
|
14
|
+
\u001B[96mThe project needs your help! Please consider supporting PrivacySafe on Open Collective: \u001B[0m
|
|
15
|
+
\u001B[96m>\u001B[94m https://opencollective.com/privacysafe \u001B[0m
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
function isBannerRequired() {
|
|
19
|
+
if (ADBLOCK || SILENT) { return false; }
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (isBannerRequired()) {
|
|
24
|
+
console.log(COLOR ? BANNER : BANNER.replace(/\u001B\[\d+m/g, ''));
|
|
25
|
+
}
|