@vulkano/core 1.8.0 → 1.10.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/bootstrap/server.js +28 -18
- package/libs/Download.js +23 -0
- package/package.json +1 -1
package/bootstrap/server.js
CHANGED
|
@@ -272,14 +272,35 @@ module.exports = function loadServer() {
|
|
|
272
272
|
rules: cspRules
|
|
273
273
|
} = expressConfig.csp || {};
|
|
274
274
|
|
|
275
|
-
if (cspEnabled) {
|
|
275
|
+
if (cspEnabled && cspRules) {
|
|
276
|
+
|
|
277
|
+
const cspRulesHeader = [];
|
|
278
|
+
|
|
279
|
+
if (Array.isArray(cspRules) && cspRules.length > 0) {
|
|
280
|
+
|
|
281
|
+
for ( let i = 0; i < cspRules.length; i += 1) {
|
|
282
|
+
cspRulesHeader.push(cspRules[i]);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
} else if (typeof cspRules === 'object') {
|
|
286
|
+
|
|
287
|
+
Object.keys(cspRules).forEach( (r) => {
|
|
288
|
+
const tmpValues = cspRules[r];
|
|
289
|
+
if (Array.isArray(tmpValues)) {
|
|
290
|
+
cspRulesHeader.push(`${r} ${tmpValues.join(' ')}`);
|
|
291
|
+
} else if (typeof tmpValues === 'string') {
|
|
292
|
+
cspRulesHeader.push(`${r} ${tmpValues}`);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
} else if (typeof cspRules === 'string') {
|
|
297
|
+
|
|
298
|
+
cspRulesHeader.push(cspRules);
|
|
276
299
|
|
|
277
|
-
if (!Array.isArray(cspRules)) {
|
|
278
|
-
console.error('Vulkano Error: ', 'The Content Security Policy Rules must be an array');
|
|
279
|
-
return;
|
|
280
300
|
}
|
|
281
301
|
|
|
282
|
-
|
|
302
|
+
// Has Rules
|
|
303
|
+
if (cspRulesHeader.length > 0) {
|
|
283
304
|
|
|
284
305
|
vulkano.use( (req, res, next) => {
|
|
285
306
|
|
|
@@ -287,7 +308,7 @@ module.exports = function loadServer() {
|
|
|
287
308
|
res.setHeader('Report-To', JSON.stringify(cspReportTo));
|
|
288
309
|
}
|
|
289
310
|
|
|
290
|
-
res.setHeader('Content-Security-Policy',
|
|
311
|
+
res.setHeader('Content-Security-Policy', cspRulesHeader.join('; '));
|
|
291
312
|
|
|
292
313
|
next();
|
|
293
314
|
|
|
@@ -409,11 +430,8 @@ module.exports = function loadServer() {
|
|
|
409
430
|
|
|
410
431
|
// ---------------
|
|
411
432
|
// PUBLIC PATH - File: app/config/settings.js
|
|
412
|
-
// (if are using Vite)
|
|
413
433
|
// ---------------
|
|
414
|
-
|
|
415
|
-
vulkano.use(express.static(PUBLIC_PATH));
|
|
416
|
-
}
|
|
434
|
+
vulkano.use(express.static(PUBLIC_PATH));
|
|
417
435
|
|
|
418
436
|
// ---------------
|
|
419
437
|
// ROUTES
|
|
@@ -558,14 +576,6 @@ module.exports = function loadServer() {
|
|
|
558
576
|
}
|
|
559
577
|
});
|
|
560
578
|
|
|
561
|
-
// ---------------
|
|
562
|
-
// PUBLIC PATH
|
|
563
|
-
// (if not are using Vite)
|
|
564
|
-
// ---------------
|
|
565
|
-
if (app.viteProxy) {
|
|
566
|
-
vulkano.use(express.static(PUBLIC_PATH));
|
|
567
|
-
}
|
|
568
|
-
|
|
569
579
|
app.vulkano = vulkano;
|
|
570
580
|
app.server = server;
|
|
571
581
|
|
package/libs/Download.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
const http = require('http');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
|
|
5
|
+
module.exports = (url, dest) => {
|
|
6
|
+
|
|
7
|
+
const file = fs.createWriteStream(dest);
|
|
8
|
+
|
|
9
|
+
const protocol = (url.indexOf('http:') >= 0) ? http : https;
|
|
10
|
+
|
|
11
|
+
return new Promise( (resolve, reject) => {
|
|
12
|
+
protocol.get(url, (response) => {
|
|
13
|
+
response.pipe(file);
|
|
14
|
+
file.on('finish', () => {
|
|
15
|
+
file.close(resolve);
|
|
16
|
+
});
|
|
17
|
+
file.on('error', (error) => {
|
|
18
|
+
reject(error);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
};
|