mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
LibreJS runs a page's JavaScript only when it can tell the code is free.
A Meteor bundle is generated, minified and named by hash, so it cannot
carry per-file @license comments; LibreJS's other way is a JS Web Labels
table, linked with rel="jslicense". WeKan now serves /jslicense.html,
built from the client bundle it is actually serving (web.browser and
web.browser.legacy, under ROOT_URL's path), labelling each script with
the free licenses the bundle combines - Expat (MIT), Apache-2.0, Modified
BSD, FreeBSD and ISC, under LibreJS's own names and addresses - and with
WeKan's source at the running version. Every page links it from <head>,
whether or not the custom head is on.
models/lib/jsWebLabels.js builds the table and the link;
tests/jsWebLabels.test.cjs checks the scripts chosen from a manifest, the
table LibreJS reads, escaping and the wiring. releases/risk-baseline.json
allows the license addresses, and ntfy.sh, which the ntfy channel
(d873af70e8) names in a placeholder and comments.
Thanks to alexgleason and xet7 !
Fixes #1040.
26 lines
1.0 KiB
JavaScript
26 lines
1.0 KiB
JavaScript
// #1040: the JS Web Labels page LibreJS reads (models/lib/jsWebLabels.js),
|
|
// built from the client bundle this server is serving.
|
|
import { WebApp } from 'meteor/webapp';
|
|
|
|
const { bundleScripts, renderJsWebLabels } = require('/models/lib/jsWebLabels');
|
|
|
|
function prefix() {
|
|
return (typeof __meteor_runtime_config__ !== 'undefined' && __meteor_runtime_config__.ROOT_URL_PATH_PREFIX) || '';
|
|
}
|
|
|
|
WebApp.handlers.get('/jslicense.html', (req, res) => {
|
|
try {
|
|
const programs = WebApp.clientPrograms || {};
|
|
const scripts = [...new Set(['web.browser', 'web.browser.legacy']
|
|
.flatMap(arch => bundleScripts(programs[arch] && programs[arch].manifest, prefix())))];
|
|
const version = (() => { try { return require('/package.json').version; } catch (e) { return ''; } })();
|
|
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
res.setHeader('Cache-Control', 'public, max-age=3600');
|
|
res.end(renderJsWebLabels({ scripts, version }));
|
|
} catch (error) {
|
|
res.statusCode = 500;
|
|
res.end();
|
|
}
|
|
});
|
|
|