← back to Domain Landings
chore: refactor (checkBasicAuth helper), v0.2.0 (session close)
df81e8979bc281baccc3e2360959ed9b8c976c83 · 2026-08-17 17:19:49 -0700 · Steve Abrams
Files touched
M package.jsonM server.js
Diff
commit df81e8979bc281baccc3e2360959ed9b8c976c83
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Mon Aug 17 17:19:49 2026 -0700
chore: refactor (checkBasicAuth helper), v0.2.0 (session close)
---
package.json | 2 +-
server.js | 25 +++++++++++--------------
2 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/package.json b/package.json
index ec4f910..0139c16 100644
--- a/package.json
+++ b/package.json
@@ -1 +1 @@
-{"name":"domain-landings","version":"0.1.0","private":true,"main":"server.js","scripts":{"start":"node server.js"}}
+{"name":"domain-landings","version":"0.2.0","private":true,"main":"server.js","scripts":{"start":"node server.js"}}
\ No newline at end of file
diff --git a/server.js b/server.js
index 21af630..ad240e0 100644
--- a/server.js
+++ b/server.js
@@ -148,13 +148,17 @@ async function forwardGeorge(payload) {
});
}
-function adminInquiries(req, res) {
- const hdr = req.headers.authorization || '';
+function checkBasicAuth(req, res, realm) {
const want = 'Basic ' + Buffer.from(BASIC_AUTH).toString('base64');
- if (hdr !== want) {
- res.writeHead(401, { 'WWW-Authenticate': 'Basic realm="offers"' }).end('auth required');
- return;
+ if ((req.headers.authorization || '') !== want) {
+ res.writeHead(401, { 'WWW-Authenticate': `Basic realm="${realm}"` }).end('auth required');
+ return false;
}
+ return true;
+}
+
+function adminInquiries(req, res) {
+ if (!checkBasicAuth(req, res, 'offers')) return;
let rows = [];
try {
rows = fs.readFileSync(INQ, 'utf8').split('\n').filter(Boolean).map(l => JSON.parse(l)).reverse();
@@ -178,12 +182,7 @@ ${cards || '<p class="empty">No offers yet.</p>'}`);
}
function adminWall(req, res) {
- const hdr = req.headers.authorization || '';
- const want = 'Basic ' + Buffer.from(BASIC_AUTH).toString('base64');
- if (hdr !== want) {
- res.writeHead(401, { 'WWW-Authenticate': 'Basic realm="wall"' }).end('auth required');
- return;
- }
+ if (!checkBasicAuth(req, res, 'wall')) return;
let sites = [];
try { sites = JSON.parse(fs.readFileSync(path.join(__dirname, 'data/all-sites.json'), 'utf8')); } catch {}
// mark which domains actually have a thumbnail so the client never requests a missing one (no 404s)
@@ -288,9 +287,7 @@ const server = http.createServer((req, res) => {
}
if (req.method === 'GET' && req.url.startsWith('/thumbs/')) {
// same gate as the wall — the authenticated wall page's <img> requests carry the creds
- if ((req.headers.authorization || '') !== 'Basic ' + Buffer.from(BASIC_AUTH).toString('base64')) {
- res.writeHead(401, { 'WWW-Authenticate': 'Basic realm="wall"' }).end('auth required'); return;
- }
+ if (!checkBasicAuth(req, res, 'wall')) return;
const name = path.basename(req.url.split('?')[0]); // <domain>.jpg
if (!/^[a-z0-9.\-]+\.jpg$/i.test(name)) { res.writeHead(400).end(); return; }
const fp = path.join(__dirname, 'data/thumbs', name);
← 8bfdf53 5x: contrarian-gate fixes verified + report updated
·
back to Domain Landings
·
wall: add per-chip open-in-new-window control (↗ open button e79003b →