diff --git a/server.js b/server.js index 521c55a..819d6be 100644 --- a/server.js +++ b/server.js @@ -234,6 +234,13 @@ const server = http.createServer(async (req, res) => { // -- pages if (req.method === 'GET' || req.method === 'HEAD') { + // old site links (2026-11-13): referral links were /? (bare query) and pages were *.php. An old username maps to + // the same person's network username (oldrefs.json, matched by email); a page address goes home. + if (/\.php$/i.test(p) || (p === '/' && /^[A-Za-z0-9_.-]{2,40}$/.test(u.search.slice(1).split('&')[0]))) { // "&fbclid=..." may follow + const old = /\.php$/i.test(p) && p !== '/index.php' ? '' : u.search.slice(1).split('&')[0].toLowerCase(); + let OR = {}; try { OR = JSON.parse(fs.readFileSync(path.join(C.dataDir, 'oldrefs.json'), 'utf8')); } catch (e) {} + const net = old && OR[old]; res.writeHead(301, { Location: net ? '/?ref=' + encodeURIComponent(net) : '/', 'Cache-Control': 'no-store' }); return res.end(); + } const PAGES = { '/': 'index.html', '/board': 'board.html', '/join': 'join.html', '/my': 'my.html', '/how': 'how.html', '/ledger': 'ledger.html', '/contract': 'contract.html' }; if (PAGES[p]) { const set = []; @@ -259,13 +266,6 @@ const server = http.createServer(async (req, res) => { const name = path.basename(p); if (!/^[a-z0-9-]+\.(png|jpg|gif)$/.test(name)) { res.writeHead(404); return res.end(); } return sendFile(res, path.join(C.dataDir, 'art', name), { 'Cache-Control': 'public, max-age=86400' }); } - // old site links (2026-11-13): referral links were /? (bare query) and pages were *.php. An old username maps to - // the same person's network username (oldrefs.json, matched by email); a page address goes home. - if (/\.php$/i.test(p) || (p === '/' && /^[A-Za-z0-9_.-]{2,40}$/.test(u.search.slice(1).split('&')[0]))) { // "&fbclid=..." may follow - const old = /\.php$/i.test(p) && p !== '/index.php' ? '' : u.search.slice(1).split('&')[0].toLowerCase(); - let OR = {}; try { OR = JSON.parse(fs.readFileSync(path.join(C.dataDir, 'oldrefs.json'), 'utf8')); } catch (e) {} - const net = old && OR[old]; res.writeHead(301, { Location: net ? '/?ref=' + encodeURIComponent(net) : '/', 'Cache-Control': 'no-store' }); return res.end(); - } const wm = /^\/w\/([a-z0-9]{8,16})$/.exec(p); if (wm) { const ok = !!WELCOME()[wm[1]];