Viral links served in place, not redirected: Facebook follows redirects and og:url, so every share was losing the member's name; og:url now carries the ref, canonical stays clean; QA walk updated
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -1078,8 +1078,10 @@ const server = http.createServer(async (req, res) => {
|
||||
if (req.method === 'GET' && (TRAFFIC_PAGES.has(p) || /^\/(join|from|wall|blog)\/[^/]+$/.test(p))) traffic.hit(p.startsWith('/blog/') ? '/blog/*' : p, req.headers.referer, req.headers['user-agent']);
|
||||
// -- viral links (Marty, 2026-09-21): ANY public page + ?ref=<username|code|id> is that member's
|
||||
// referral link. Same 30-day last-touch sponsor cookie as /join, the view counts under the
|
||||
// "page" hook in link stats, then a redirect to the clean URL so canonical links stay clean
|
||||
// for search engines. /join, /from and the APIs keep their own meaning of ?ref.
|
||||
// "page" hook in link stats. Served IN PLACE, not redirected (2026-09-21): Facebook's crawler follows
|
||||
// redirects and canonicalizes a share to og:url, so the redirect (and a clean og:url) dropped the member's
|
||||
// name from every share. og:url now carries the ref; rel=canonical stays clean for search engines.
|
||||
// /join, /from and the APIs keep their own meaning of ?ref.
|
||||
if ((req.method === 'GET' || req.method === 'HEAD') && u.searchParams.has('ref') && !p.startsWith('/api/') && !p.startsWith('/admin') && !/^\/(join|from)\//.test(p) && !/\.[a-z0-9]{2,5}$/i.test(p)) {
|
||||
const raw = String(u.searchParams.get('ref') || '').trim().toLowerCase().slice(0, 40);
|
||||
const tok = JOIN_ALIASES[raw] || raw;
|
||||
@@ -1095,8 +1097,25 @@ const server = http.createServer(async (req, res) => {
|
||||
if (!parseCookies(req)['iap.ref']) set.push('iap.ref=' + encodeURIComponent(coach.refHost(req.headers.referer)) + cookieTail); // first-touch source
|
||||
if (req.method === 'GET') coach.recordView(tok, 'page', req.headers.referer);
|
||||
}
|
||||
res.writeHead(302, baseHeaders(Object.assign({ Location: clean, 'Cache-Control': 'no-store' }, set.length ? { 'Set-Cookie': set } : {})));
|
||||
return res.end();
|
||||
if (known) {
|
||||
const wh = res.writeHead.bind(res); let html = false;
|
||||
res.writeHead = function (code, headers) {
|
||||
headers = Object.assign({}, headers || {});
|
||||
if (set.length) headers['Set-Cookie'] = [].concat(headers['Set-Cookie'] || [], set);
|
||||
html = /text\/html/i.test(String(headers['Content-Type'] || '')); if (html) delete headers['Content-Length'];
|
||||
return wh(code, headers);
|
||||
};
|
||||
const end = res.end.bind(res);
|
||||
res.end = function (chunk, enc, cb) {
|
||||
if (html && chunk) {
|
||||
let s = Buffer.isBuffer(chunk) ? chunk.toString('utf8') : String(chunk);
|
||||
s = s.replace(/(<meta property="og:url" content=")([^"]*)(")/, (m, a, url, c) => a + url + (url.includes('?') ? '&' : '?') + 'ref=' + encodeURIComponent(tok) + c);
|
||||
return end(s, 'utf8', cb);
|
||||
}
|
||||
return end(chunk, enc, cb);
|
||||
};
|
||||
}
|
||||
req.url = clean; // the routes below see the clean path; u already has the ref removed
|
||||
}
|
||||
// -- join links: /join/<memberId or share code> — LAST-touch cookie (Marty,
|
||||
// 2026-09-10): the link a visitor opened most recently is the sponsor shown
|
||||
|
||||
Reference in New Issue
Block a user