openvibers/openvibe.finance Commits
Our own files by their content (#12)
Changes
@@@ -9,6 +9,22 @@ const serve = require('openvibe-shared/serve');const { CATEGORIES, KINDS } = require('./store');const { payoff, faster, perMonth } = require('./plan');++// Our own files by their content (a release's change is a new address, so neither a browser nor Cloudflare keeps an old++// one for the hour they may cache it): /x.css?v=<first 10 hex of its sha256>, read once at boot.++const asset = (() => {++ const fs = require('node:fs');++ const crypto = require('node:crypto');++ const kept = new Map();++ return (name) => {++ if (!kept.has(name)) {++ let v = 'dev';++ try { v = crypto.createHash('sha256').update(fs.readFileSync(require('node:path').join(__dirname, '..', 'public', name))).digest('hex').slice(0, 10); } catch { /* missing in a test: unversioned */ }++ kept.set(name, `/${name}?v=${v}`);++ }++ return kept.get(name);++ };++})();++const SITE = 'https://openvibe.finance';const esc = (v) => String(v == null ? '' : v).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));const money = (cents, currency = 'USD') => {@@@ -24,7 +40,7 @@ function page({ title, body, path = '/', description = 'Your money, your rules,name: 'OpenVibe.Finance', siteName: 'OpenVibe.Finance', title, description, canonical: `${SITE}${path}`, robots,navbar: { service: 'finance', apiBase: 'https://openvibe.network', links: [{ label: 'Money', href: '/' }, { label: 'This month', href: '/month' }, { label: 'Recurring', href: '/bills' }, { label: 'Goals', href: '/goals' }, { label: 'What if', href: '/ahead' }] },footer: { service: 'finance', variant: 'full', mount: '#ov-footer' },-- head: `<link rel="stylesheet" href="${serve.url('kit.css')}"><link rel="stylesheet" href="/finance.css"><script src="/finance.js" defer></script>`,++ head: `<link rel="stylesheet" href="${serve.url('kit.css')}"><link rel="stylesheet" href="${asset('finance.css')}"><script src="${asset('finance.js')}" defer></script>`,body: `<div id="navbar-mount"></div><main id="main" class="ovk-page fin">${body}</main>`,});}@@@ -46,6 +46,7 @@ const SAME = { 'sec-fetch-site': 'same-origin' };assert.strictEqual(home.status, 200);assert.match(home.text, /Your money, your rules, your data/);assert.match(home.text, /No money moves/);++ assert.match(home.text, /href="\/finance\.css\?v=[0-9a-f]{10}"><script src="\/finance\.js\?v=[0-9a-f]{10}" defer>/, 'our files by their content');assert.strictEqual(home.headers.get('cache-control'), 'private, no-store');const month = await go('/month');assert.strictEqual(month.status, 303);
@@ -9,6 +9,22 @@ const serve = require('openvibe-shared/serve');
@@ -9,6 +9,22 @@ const serve = require('openvibe-shared/serve');
const { CATEGORIES, KINDS } = require('./store');
const { CATEGORIES, KINDS } = require('./store');
const { payoff, faster, perMonth } = require('./plan');
const { payoff, faster, perMonth } = require('./plan');
+// Our own files by their content (a release's change is a new address, so neither a browser nor Cloudflare keeps an old
+// one for the hour they may cache it): /x.css?v=<first 10 hex of its sha256>, read once at boot.
+const asset = (() => {
+ const fs = require('node:fs');
+ const crypto = require('node:crypto');
+ const kept = new Map();
+ return (name) => {
+ if (!kept.has(name)) {
+ let v = 'dev';
+ try { v = crypto.createHash('sha256').update(fs.readFileSync(require('node:path').join(__dirname, '..', 'public', name))).digest('hex').slice(0, 10); } catch { /* missing in a test: unversioned */ }
+ kept.set(name, `/${name}?v=${v}`);
+ }
+ return kept.get(name);
+ };
+})();
+
const SITE = 'https://openvibe.finance';
const SITE = 'https://openvibe.finance';
const esc = (v) => String(v == null ? '' : v).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
const esc = (v) => String(v == null ? '' : v).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
const money = (cents, currency = 'USD') => {
const money = (cents, currency = 'USD') => {
@@ -24,7 +40,7 @@ function page({ title, body, path = '/', description = 'Your money, your rules,
@@ -24,7 +40,7 @@ function page({ title, body, path = '/', description = 'Your money, your rules,
name: 'OpenVibe.Finance', siteName: 'OpenVibe.Finance', title, description, canonical: `${SITE}${path}`, robots,
name: 'OpenVibe.Finance', siteName: 'OpenVibe.Finance', title, description, canonical: `${SITE}${path}`, robots,
navbar: { service: 'finance', apiBase: 'https://openvibe.network', links: [{ label: 'Money', href: '/' }, { label: 'This month', href: '/month' }, { label: 'Recurring', href: '/bills' }, { label: 'Goals', href: '/goals' }, { label: 'What if', href: '/ahead' }] },
navbar: { service: 'finance', apiBase: 'https://openvibe.network', links: [{ label: 'Money', href: '/' }, { label: 'This month', href: '/month' }, { label: 'Recurring', href: '/bills' }, { label: 'Goals', href: '/goals' }, { label: 'What if', href: '/ahead' }] },
footer: { service: 'finance', variant: 'full', mount: '#ov-footer' },
footer: { service: 'finance', variant: 'full', mount: '#ov-footer' },
- head: `<link rel="stylesheet" href="${serve.url('kit.css')}"><link rel="stylesheet" href="/finance.css"><script src="/finance.js" defer></script>`,
+ head: `<link rel="stylesheet" href="${serve.url('kit.css')}"><link rel="stylesheet" href="${asset('finance.css')}"><script src="${asset('finance.js')}" defer></script>`,
body: `<div id="navbar-mount"></div><main id="main" class="ovk-page fin">${body}</main>`,
body: `<div id="navbar-mount"></div><main id="main" class="ovk-page fin">${body}</main>`,
});
});
}
}
@@ -46,6 +46,7 @@ const SAME = { 'sec-fetch-site': 'same-origin' };
@@ -46,6 +46,7 @@ const SAME = { 'sec-fetch-site': 'same-origin' };
assert.strictEqual(home.status, 200);
assert.strictEqual(home.status, 200);
assert.match(home.text, /Your money, your rules, your data/);
assert.match(home.text, /Your money, your rules, your data/);
assert.match(home.text, /No money moves/);
assert.match(home.text, /No money moves/);
+ assert.match(home.text, /href="\/finance\.css\?v=[0-9a-f]{10}"><script src="\/finance\.js\?v=[0-9a-f]{10}" defer>/, 'our files by their content');
assert.strictEqual(home.headers.get('cache-control'), 'private, no-store');
assert.strictEqual(home.headers.get('cache-control'), 'private, no-store');
const month = await go('/month');
const month = await go('/month');
assert.strictEqual(month.status, 303);
assert.strictEqual(month.status, 303);