Files
wekan/models/lib/dynamicImportOrigin.js
T
Lauri Ojansivu 7514d6e175 UCS: avatars show again after an upgrade, and lazily loaded code is fetched from the page's own address.
On Univention WeKan is served at /wekan. profile.avatarUrl holds
/cdn/storage/avatars/<id> - what Change Avatar and the server's own
migrations store - and it was rendered as stored, so the browser asked
the UCS web server for a path outside WeKan, got 404, and every avatar
was an empty circle, while Change Avatar, which builds its own link,
showed the picture. models/lib/avatarDisplayUrl.js treats the stored
value as the avatar's name: whatever host or old path prefix stood
before /cdn/storage/avatars/ or /cfs/files/avatars/ is replaced with the
path WeKan is served at now, relative to the page's origin. The avatar,
the People page and the report tables draw through it; the default
avatar gets the prefix too. External pictures and data: URLs are left
alone.

The same session, opened through 127.0.0.1:8443/wekan, fetched lazily
loaded code from ROOT_URL's host ucs-2275.wekan.intranet, which the
browser could not resolve (NS_ERROR_UNKNOWN_HOST, "Cross-Origin Request
Blocked"). Meteor's dynamic-import setting useLocationOrigin is now on
by default, so that code comes from the page's own origin and ROOT_URL
path; an explicit value in METEOR_SETTINGS still wins. Links keep using
ROOT_URL as before.

tests/avatarDisplayUrl.test.cjs covers every stored shape, (negative)
leaves external, data: and query-string URLs alone, checks that no
template puts a stored avatar URL in src without avatarSrc, and pins the
dynamic-import default and its override. The Playwright spec
avatar-sub-path.e2e.js checks the drawn src and the setting in a browser;
it was not run here.

Thanks to xet7 !
2026-10-12 01:30:07 +03:00

33 lines
1.7 KiB
JavaScript

'use strict';
// Where the browser fetches lazily loaded code from.
//
// Meteor's dynamic-import fetches every import() the first page load did not
// include from Meteor.absoluteUrl('__meteor__/dynamic-import/fetch') - that is,
// from ROOT_URL's HOST. A browser that reached WeKan by another name or an IP
// cannot always resolve or reach that host: on Univention (UCS) opened through
// 127.0.0.1:8443/wekan, the fetch went to the ROOT_URL host
// ucs-2275.wekan.intranet, failed with NS_ERROR_UNKNOWN_HOST ("Cross-Origin
// Request Blocked ... CORS request did not succeed"), and the parts of WeKan
// loaded that way never arrived.
//
// Meteor has the setting for this: dynamic-import's useLocationOrigin fetches
// from the page's own origin plus ROOT_URL's path prefix - the one address the
// browser has proved it can reach, since it loaded the page from it. This is
// loading WeKan's own code, not a link anybody shares, so it does not touch
// the rule in browserRootUrl.js that a real ROOT_URL wins for links.
//
// An administrator who set packages.dynamic-import.useLocationOrigin in
// METEOR_SETTINGS keeps their value, false included.
function applyDynamicImportOrigin(publicSettings) {
const settings = publicSettings || {};
if (!settings.packages || typeof settings.packages !== 'object') settings.packages = {};
const current = settings.packages['dynamic-import'];
const dynamicImport = current && typeof current === 'object' ? current : {};
if (typeof dynamicImport.useLocationOrigin !== 'boolean') dynamicImport.useLocationOrigin = true;
settings.packages['dynamic-import'] = dynamicImport;
return settings;
}
module.exports = { applyDynamicImportOrigin };