diff options
| author | alex <[email protected]> | 2026-11-10 20:54:44 +0100 |
|---|---|---|
| committer | alex <[email protected]> | 2026-11-10 20:54:44 +0100 |
| commit | 5bdac896f505b850142682a12e3f5961f775efb7 (patch) | |
| tree | 766ded4a9dd6b1e84339432cfcaa3862c13c4984 /scripts/spin.js | |
| download | wheel-of-names-clone.git-5bdac896f505b850142682a12e3f5961f775efb7.tar.xz wheel-of-names-clone.git-5bdac896f505b850142682a12e3f5961f775efb7.zip | |
init
Diffstat (limited to 'scripts/spin.js')
| -rw-r--r-- | scripts/spin.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/spin.js b/scripts/spin.js new file mode 100644 index 0000000..7b9411e --- /dev/null +++ b/scripts/spin.js @@ -0,0 +1,37 @@ +#!/usr/bin/env node + +const winner = process.argv[2]; + +if (!winner) { + console.error("Usage: npm run spin -- \"Winner Name\""); + process.exit(1); +} + +const endpoint = process.env.WHEEL_URL || "http://localhost:3000"; + +const main = async () => { + const response = await fetch(`${endpoint}/api/spin`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ winner }), + }); + + const data = await response.json(); + + if (!response.ok) { + console.error("Spin failed:", data.error || "unknown error"); + if (Array.isArray(data.entries)) { + console.error("Available entries:", data.entries.join(", ")); + } + process.exit(1); + } + + console.log(`Spinning wheel. Winner set to: ${data.spin.winner}`); +}; + +main().catch((error) => { + console.error("Request failed:", error.message); + process.exit(1); +}); |
