Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Show HN: I made a pointless button website.
```js const config = { sleep: 10, max_requests: 20, log_time: 100, };
async function sleep(ms) { return new Promise((res) => setTimeout(res, ms)); }
async function click() { const res = await fetch("https://obscurebutton.com/api/clicks", { headers: { "content-type": "application/json", }, body: JSON.stringify({ increment: 10 }), method: "POST", });
try { return (await res.json()).count; } catch (e) { return 0; }
void (async function main() { let countOld = 0; let countNew = 0; let activeReqs = 0;
setInterval(() => { console.log( `[${activeReqs}] ${countOld} (${((countNew - countOld) / config.log_time) * 1000}/sec)` ); countOld = countNew; }, config.log_time); setInterval(async () => { if (activeReqs >= config.max_requests) return; activeReqs++; countNew = (await click()) || countNew; activeReqs--; }, config.sleep);
Also in the future, do some input validation. Removing the `content-type` header causes a 502 internal server error to be returned.
There are no comments on this comment yet.
```js const config = { sleep: 10, max_requests: 20, log_time: 100, };
async function sleep(ms) { return new Promise((res) => setTimeout(res, ms)); }
async function click() { const res = await fetch("https://obscurebutton.com/api/clicks", { headers: { "content-type": "application/json", }, body: JSON.stringify({ increment: 10 }), method: "POST", });
}void (async function main() { let countOld = 0; let countNew = 0; let activeReqs = 0;
})(); ```Also in the future, do some input validation. Removing the `content-type` header causes a 502 internal server error to be returned.