openvibers/openvibe.markets Commits
Our own files by their content (#2)
Changes
@@@ -7,6 +7,22 @@ const shell = require('openvibe-shared/shell');const serve = require('openvibe-shared/serve');const { PLACES } = require('./elsewhere');++// 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.markets';const esc = (v) => String(v == null ? '' : v).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));const money = (n, currency = 'USD') => {@@@ -28,7 +44,7 @@ function page({ title, body, path = '/', description = 'Every marketplace, one sname: 'OpenVibe.Markets', siteName: 'OpenVibe.Markets', title, description, canonical: `${SITE}${path}`, robots,navbar: { service: 'markets', apiBase: 'https://openvibe.network', links: [{ label: 'Search', href: '/' }, { label: 'Deals', href: 'https://openvibe.deals/' }] },footer: { service: 'markets', variant: 'full', mount: '#ov-footer' },-- head: `<link rel="stylesheet" href="${serve.url('kit.css')}"><link rel="stylesheet" href="/markets.css">`,++ head: `<link rel="stylesheet" href="${serve.url('kit.css')}"><link rel="stylesheet" href="${asset('markets.css')}">`,body: `<div id="navbar-mount"></div><main id="main" class="ovk-page mk">${body}</main>`,});}@@@ -53,6 +53,7 @@ const OFFERS = [assert.match(r.text, /Facebook Marketplace/);assert.match(r.text, /data-ov-trending="own"/, 'a product search keeps its own examples, never the page\'s headings');assert.match(r.headers.get('cache-control'), /public/);++ assert.match(r.text, /href="\/markets\.css\?v=[0-9a-f]{10}"/, 'our stylesheet by its content: a release is a new address');r = await get('/search?q=headphones');assert.strictEqual(r.status, 200);
@@ -7,6 +7,22 @@ const shell = require('openvibe-shared/shell');
@@ -7,6 +7,22 @@ const shell = require('openvibe-shared/shell');
const serve = require('openvibe-shared/serve');
const serve = require('openvibe-shared/serve');
const { PLACES } = require('./elsewhere');
const { PLACES } = require('./elsewhere');
+// 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.markets';
const SITE = 'https://openvibe.markets';
const esc = (v) => String(v == null ? '' : v).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
const esc = (v) => String(v == null ? '' : v).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
const money = (n, currency = 'USD') => {
const money = (n, currency = 'USD') => {
@@ -28,7 +44,7 @@ function page({ title, body, path = '/', description = 'Every marketplace, one s
@@ -28,7 +44,7 @@ function page({ title, body, path = '/', description = 'Every marketplace, one s
name: 'OpenVibe.Markets', siteName: 'OpenVibe.Markets', title, description, canonical: `${SITE}${path}`, robots,
name: 'OpenVibe.Markets', siteName: 'OpenVibe.Markets', title, description, canonical: `${SITE}${path}`, robots,
navbar: { service: 'markets', apiBase: 'https://openvibe.network', links: [{ label: 'Search', href: '/' }, { label: 'Deals', href: 'https://openvibe.deals/' }] },
navbar: { service: 'markets', apiBase: 'https://openvibe.network', links: [{ label: 'Search', href: '/' }, { label: 'Deals', href: 'https://openvibe.deals/' }] },
footer: { service: 'markets', variant: 'full', mount: '#ov-footer' },
footer: { service: 'markets', variant: 'full', mount: '#ov-footer' },
- head: `<link rel="stylesheet" href="${serve.url('kit.css')}"><link rel="stylesheet" href="/markets.css">`,
+ head: `<link rel="stylesheet" href="${serve.url('kit.css')}"><link rel="stylesheet" href="${asset('markets.css')}">`,
body: `<div id="navbar-mount"></div><main id="main" class="ovk-page mk">${body}</main>`,
body: `<div id="navbar-mount"></div><main id="main" class="ovk-page mk">${body}</main>`,
});
});
}
}
@@ -53,6 +53,7 @@ const OFFERS = [
@@ -53,6 +53,7 @@ const OFFERS = [
assert.match(r.text, /Facebook Marketplace/);
assert.match(r.text, /Facebook Marketplace/);
assert.match(r.text, /data-ov-trending="own"/, 'a product search keeps its own examples, never the page\'s headings');
assert.match(r.text, /data-ov-trending="own"/, 'a product search keeps its own examples, never the page\'s headings');
assert.match(r.headers.get('cache-control'), /public/);
assert.match(r.headers.get('cache-control'), /public/);
+ assert.match(r.text, /href="\/markets\.css\?v=[0-9a-f]{10}"/, 'our stylesheet by its content: a release is a new address');
r = await get('/search?q=headphones');
r = await get('/search?q=headphones');
assert.strictEqual(r.status, 200);
assert.strictEqual(r.status, 200);