Files
wekan/server/productNameCache.js
T
Lauri Ojansivu 55552a7203 Snap: the pages shown without a database use the product name and the dashboard's colours.
Two things about the standalone pages the snap serves when WeKan itself cannot
be served - under maintenance, recovering data, database too old, and the new
"waiting for its database" (#6592).

THE NAME. They are a node:http server with no database connection, which is the
whole point of them, so the product name comes from a file: wekan-control caches
it once per start, right after the database comes up. That leaves the case that
matters - an admin sets the product name in the Admin Panel and the snap is not
restarted before the next outage - and a rebranded WeKan then tells its users
"WeKan is waiting for its database", a word they have never seen. WeKan is the
only thing that knows the name the moment it changes, so WeKan writes it:
server/productNameCache.js writes $SNAP_COMMON/.productname.txt at startup and
whenever the setting changes, the same way customHeadRender keeps the <title> in
step. An empty name is not written (the pages fall back to WeKan on their own),
a read-only $SNAP_COMMON is a warning and nothing more, and off snap there is no
SNAP_COMMON and nothing happens at all.

THE COLOURS. The schema-upgrade dashboard (/schema-upgrade-status) and these
pages are the same thing to a reader: the product saying what it is doing while
it cannot show them the app. They now look like it - the dashboard's #111
ground, #ddd text, #7bf blue and monospace face, dark only as the dashboard is,
rather than a light card that reads as a different product one page over.

Thanks to xet7 !
2026-08-13 19:44:15 +03:00

68 lines
3.0 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import fs from 'fs';
import path from 'path';
import Settings from '/models/settings';
// The Admin Panel product name, written to a file so the pages that are shown
// when the DATABASE IS NOT AVAILABLE can still use it.
//
// The snap's maintenance pages (bin/wekan-maintenance-page.mjs: under
// maintenance, recovering data, database too old, and #6592's "waiting for its
// database") are a standalone node:http server with no database connection at
// all - that is the point of them, they are what answers while the database is
// down. So a rebranded WeKan said "WeKan is waiting for its database" to people
// who have never seen the word WeKan.
//
// wekan-control already cached the name once per start, right after the database
// came up. That leaves the case this is for: an admin sets the product name in
// the Admin Panel and the snap is not restarted before the next outage - the
// cache is then from before the rename, or missing entirely on an instance that
// has never been restarted since. WeKan itself is the only thing that knows the
// name the moment it changes, so WeKan writes it: once at startup and again
// whenever the setting changes.
//
// $SNAP_COMMON is the snap's writable directory and the only place these pages
// read from; without it (Docker, source, Sandstorm) there is nothing to do and
// nothing is written.
const CACHE_DIR = process.env.SNAP_COMMON || '';
const CACHE_FILE = CACHE_DIR ? path.join(CACHE_DIR, '.productname.txt') : '';
let lastWritten = null;
export function writeProductNameCache(productName) {
if (!CACHE_FILE) return false;
const name = typeof productName === 'string' ? productName.trim() : '';
// An empty product name means "no branding set", and the pages fall back to
// WeKan on their own. Writing an empty file would make them show nothing.
if (!name) return false;
if (name === lastWritten) return false;
try {
fs.writeFileSync(CACHE_FILE, `${name}\n`, 'utf8');
lastWritten = name;
return true;
} catch (error) {
// Best effort by design: a read-only or full $SNAP_COMMON must never stop
// WeKan from starting, and the pages have their fallback.
console.warn('[product-name-cache] could not write', CACHE_FILE, '-', error.message);
return false;
}
}
if (CACHE_FILE) {
Meteor.startup(async () => {
try {
const setting = await Settings.findOneAsync();
writeProductNameCache(setting && setting.productName);
} catch (error) {
console.warn('[product-name-cache] could not read the setting at startup -', error.message);
}
// Same shape as server/lib/customHeadRender.js, which keeps the <title> in
// step with this setting: the Admin Panel writes the settings document, so
// the change arrives here without a restart.
Settings.find({}, { fields: { productName: 1 } }).observeChanges({
added(_id, fields) { writeProductNameCache(fields && fields.productName); },
changed(_id, fields) { writeProductNameCache(fields && fields.productName); },
});
});
}