@soundworks/core 3.1.0-beta.4 → 3.1.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/package.json +14 -14
- package/server/Server.js +46 -3
- package/server/utils/logger.js +24 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soundworks/core",
|
|
3
|
-
"version": "3.1.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "full-stack javascript framework for distributed audio visual experiences on the web",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Benjamin Matuszewski",
|
|
@@ -33,34 +33,34 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"chalk": "^4.1.2",
|
|
36
|
-
"columnify": "^1.
|
|
36
|
+
"columnify": "^1.6.0",
|
|
37
37
|
"compression": "^1.7.1",
|
|
38
|
-
"debug": "^4.
|
|
38
|
+
"debug": "^4.3.4",
|
|
39
39
|
"fast-deep-equal": "^3.1.3",
|
|
40
40
|
"fast-text-encoding": "^1.0.0",
|
|
41
41
|
"isomorphic-ws": "^4.0.1",
|
|
42
|
-
"keyv": "^4.
|
|
42
|
+
"keyv": "^4.2.2",
|
|
43
43
|
"keyv-file": "^0.2.0",
|
|
44
44
|
"lodash.clonedeep": "^4.5.0",
|
|
45
45
|
"lodash.merge": "^4.6.2",
|
|
46
|
-
"pem": "^1.
|
|
46
|
+
"pem": "^1.14.6",
|
|
47
47
|
"polka": "^0.5.2",
|
|
48
|
-
"serve-static": "^1.
|
|
48
|
+
"serve-static": "^1.15.0",
|
|
49
49
|
"uuid": "^8.3.2",
|
|
50
50
|
"window-or-global": "^1.0.1",
|
|
51
|
-
"ws": "^8.
|
|
51
|
+
"ws": "^8.5.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@babel/cli": "^7.
|
|
55
|
-
"@babel/core": "^7.
|
|
56
|
-
"@babel/preset-env": "^7.
|
|
57
|
-
"chai": "^4.
|
|
58
|
-
"chokidar": "^3.
|
|
54
|
+
"@babel/cli": "^7.17.6",
|
|
55
|
+
"@babel/core": "^7.17.9",
|
|
56
|
+
"@babel/preset-env": "^7.16.11",
|
|
57
|
+
"chai": "^4.3.6",
|
|
58
|
+
"chokidar": "^3.5.3",
|
|
59
59
|
"chokidar-cli": "^3.0.0",
|
|
60
60
|
"docdash": "^1.2.0",
|
|
61
|
-
"jsdoc": "^3.6.
|
|
61
|
+
"jsdoc": "^3.6.10",
|
|
62
62
|
"markdown-toc": "^1.2.0",
|
|
63
|
-
"mocha": "^9.
|
|
63
|
+
"mocha": "^9.2.2"
|
|
64
64
|
},
|
|
65
65
|
"optionalDependencies": {
|
|
66
66
|
"bufferutil": "^4.0.5",
|
package/server/Server.js
CHANGED
|
@@ -237,7 +237,8 @@ class Server {
|
|
|
237
237
|
path: 'socket',
|
|
238
238
|
pingInterval: 5000
|
|
239
239
|
},
|
|
240
|
-
useHttps: false
|
|
240
|
+
useHttps: false,
|
|
241
|
+
crossOriginIsolated: true
|
|
241
242
|
},
|
|
242
243
|
app: {
|
|
243
244
|
name: 'soundworks'
|
|
@@ -264,7 +265,37 @@ class Server {
|
|
|
264
265
|
}
|
|
265
266
|
}
|
|
266
267
|
|
|
267
|
-
this._clientConfigFunction = clientConfigFunction;
|
|
268
|
+
this._clientConfigFunction = clientConfigFunction; // basic http authentication
|
|
269
|
+
|
|
270
|
+
if (this.config.env.auth) {
|
|
271
|
+
this.router.use((req, res, next) => {
|
|
272
|
+
const isProtected = this.config.env.auth.clients.map(type => req.path.endsWith(`/${type}`)).reduce((acc, value) => acc || value, false);
|
|
273
|
+
|
|
274
|
+
if (isProtected) {
|
|
275
|
+
// authentication middleware
|
|
276
|
+
const auth = this.config.env.auth; // parse login and password from headers
|
|
277
|
+
|
|
278
|
+
const b64auth = (req.headers.authorization || '').split(' ')[1] || '';
|
|
279
|
+
const [login, password] = Buffer.from(b64auth, 'base64').toString().split(':'); // verify login and password are set and correct
|
|
280
|
+
|
|
281
|
+
if (login && password && login === auth.login && password === auth.password) {
|
|
282
|
+
// -> access granted...
|
|
283
|
+
return next();
|
|
284
|
+
} // -> access denied...
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
res.writeHead(401, {
|
|
288
|
+
'WWW-Authenticate': 'Basic',
|
|
289
|
+
'Content-Type': 'text/plain'
|
|
290
|
+
});
|
|
291
|
+
res.end('Authentication required.');
|
|
292
|
+
} else {
|
|
293
|
+
// route not protected
|
|
294
|
+
return next();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
268
299
|
return Promise.resolve();
|
|
269
300
|
}
|
|
270
301
|
/**
|
|
@@ -414,7 +445,7 @@ class Server {
|
|
|
414
445
|
}
|
|
415
446
|
}
|
|
416
447
|
|
|
417
|
-
_logger.default.clientConfigAndRouting(routes, this.config
|
|
448
|
+
_logger.default.clientConfigAndRouting(routes, this.config);
|
|
418
449
|
|
|
419
450
|
return Promise.resolve();
|
|
420
451
|
}).then(() => {
|
|
@@ -512,6 +543,18 @@ class Server {
|
|
|
512
543
|
|
|
513
544
|
if (this.config.env.subpath && !data.env.subpath) {
|
|
514
545
|
data.env.subpath = this.config.env.subpath;
|
|
546
|
+
} // cors / coop / coep headers for `crossOriginIsolated pages, enables
|
|
547
|
+
// sharedArrayBuffers and high precision timers
|
|
548
|
+
// this is the default behavior
|
|
549
|
+
// cf. https://web.dev/why-coop-coep/
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
if (this.config.env.crossOriginIsolated) {
|
|
553
|
+
res.writeHead(200, {
|
|
554
|
+
'Cross-Origin-Resource-Policy': 'same-origin',
|
|
555
|
+
'Cross-Origin-Embedder-Policy': 'require-corp',
|
|
556
|
+
'Cross-Origin-Opener-Policy': 'same-origin'
|
|
557
|
+
});
|
|
515
558
|
}
|
|
516
559
|
|
|
517
560
|
const appIndex = tmpl(data);
|
package/server/utils/logger.js
CHANGED
|
@@ -19,7 +19,10 @@ const logger = {
|
|
|
19
19
|
console.log(_chalk.default.cyan(`+ ${msg}`));
|
|
20
20
|
},
|
|
21
21
|
|
|
22
|
-
clientConfigAndRouting(routes,
|
|
22
|
+
clientConfigAndRouting(routes, config) {
|
|
23
|
+
const clientsConfig = config.app.clients;
|
|
24
|
+
const serverIp = config.env.serverIp;
|
|
25
|
+
const auth = config.env.auth;
|
|
23
26
|
const table = [];
|
|
24
27
|
|
|
25
28
|
for (let clientType in clientsConfig) {
|
|
@@ -27,18 +30,20 @@ const logger = {
|
|
|
27
30
|
|
|
28
31
|
if (client.target === 'node') {
|
|
29
32
|
const line = {
|
|
30
|
-
|
|
33
|
+
client_type: `> ${clientType}`,
|
|
31
34
|
target: _chalk.default.red(client.target),
|
|
32
35
|
path: `server ip: ${_chalk.default.green(serverIp)}`,
|
|
33
|
-
default: undefined
|
|
36
|
+
default: undefined,
|
|
37
|
+
auth: undefined
|
|
34
38
|
};
|
|
35
39
|
table.push(line);
|
|
36
40
|
} else if (client.target === 'browser') {
|
|
37
41
|
const line = {
|
|
38
|
-
|
|
42
|
+
client_type: `> ${clientType}`,
|
|
39
43
|
target: _chalk.default.red(client.target),
|
|
40
44
|
path: routes.find(r => r.clientType === clientType) ? _chalk.default.green(routes.find(r => r.clientType === clientType).path) : _chalk.default.red('no route defined'),
|
|
41
|
-
default: client.default ? '
|
|
45
|
+
default: client.default ? 'x' : undefined,
|
|
46
|
+
auth: auth && auth.clients.indexOf(clientType) !== -1 ? 'x' : undefined
|
|
42
47
|
};
|
|
43
48
|
table.push(line);
|
|
44
49
|
} else {
|
|
@@ -46,10 +51,21 @@ const logger = {
|
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
53
|
|
|
54
|
+
console.log(``);
|
|
49
55
|
console.log((0, _columnify.default)(table, {
|
|
50
|
-
showHeaders:
|
|
51
|
-
minWidth:
|
|
52
|
-
|
|
56
|
+
showHeaders: true,
|
|
57
|
+
minWidth: 6,
|
|
58
|
+
columnSplitter: ' | ',
|
|
59
|
+
config: {
|
|
60
|
+
default: {
|
|
61
|
+
align: 'center'
|
|
62
|
+
},
|
|
63
|
+
auth: {
|
|
64
|
+
align: 'center'
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
console.log(``); // check if a route is defined but not in config
|
|
53
69
|
|
|
54
70
|
const configClientTypes = Object.keys(clientsConfig);
|
|
55
71
|
routes.forEach(r => {
|