diff --git a/app.js b/app.js
index fdd9e373..47e14f70 100644
--- a/app.js
+++ b/app.js
@@ -30,7 +30,6 @@ const BIOS = [
"Will beat you at Mario Kart.",
"Currently planning the next trip."
];
-
const UNSPLASH_SEEDS = [
"1515462277126-2b47b9fa09e6",
"1520975916090-3105956dac38",
@@ -53,6 +52,14 @@ function imgFor(seed) {
function generateProfiles(count = 12) {
const profiles = [];
for (let i = 0; i < count; i++) {
+ // Pick 3 unique seeds per profile so double-tap has photos to cycle through.
+ // Fisher-Yates produces an unbiased shuffle (sort-based shuffle is biased).
+ const shuffled = [...UNSPLASH_SEEDS];
+ for (let j = shuffled.length - 1; j > 0; j--) {
+ const k = Math.floor(Math.random() * (j + 1));
+ [shuffled[j], shuffled[k]] = [shuffled[k], shuffled[j]];
+ }
+ const imgs = shuffled.slice(0, 3).map(imgFor);
profiles.push({
id: `p_${i}_${Date.now().toString(36)}`,
name: sample(FIRST_NAMES),
@@ -61,70 +68,131 @@ function generateProfiles(count = 12) {
title: sample(JOBS),
bio: sample(BIOS),
tags: pickTags(),
- img: imgFor(sample(UNSPLASH_SEEDS)),
+ imgs,
});
}
return profiles;
}
// -------------------
-// UI rendering
+// DOM refs
// -------------------
-const deckEl = document.getElementById("deck");
-const shuffleBtn = document.getElementById("shuffleBtn");
-const likeBtn = document.getElementById("likeBtn");
-const nopeBtn = document.getElementById("nopeBtn");
+const deckEl = document.getElementById("deck");
+const shuffleBtn = document.getElementById("shuffleBtn");
+const likeBtn = document.getElementById("likeBtn");
+const nopeBtn = document.getElementById("nopeBtn");
const superLikeBtn = document.getElementById("superLikeBtn");
let profiles = [];
+let dismissTimerId = null; // track in-flight dismissal timer so Shuffle can cancel it
+
+// -------------------
+// Card builder
+// -------------------
+function buildCard(p, idx, total) {
+ const card = document.createElement("article");
+ card.className = "card";
+ // Higher z-index for lower idx so profiles[0] sits on top.
+ card.style.zIndex = total - idx;
+ card.dataset.profileIdx = idx;
+ card.dataset.photoIdx = "0";
+
+ // Swipe overlay labels
+ const likeLabel = document.createElement("div");
+ likeLabel.className = "swipe-label swipe-label--like";
+ likeLabel.textContent = "LIKE";
+
+ const nopeLabel = document.createElement("div");
+ nopeLabel.className = "swipe-label swipe-label--nope";
+ nopeLabel.textContent = "NOPE";
+
+ const superLabel = document.createElement("div");
+ superLabel.className = "swipe-label swipe-label--super";
+ superLabel.textContent = "SUPER";
+
+ // Photo
+ const img = document.createElement("img");
+ img.className = "card__media";
+ img.src = p.imgs[0];
+ img.alt = `${p.name} — profile photo`;
+ img.draggable = false;
+ // Some Unsplash seeds are stale (photo removed/private). Fall back to picsum.
+ img.onerror = () => {
+ img.onerror = null; // prevent infinite error loop
+ img.src = `https://picsum.photos/seed/${p.id}-0/1200/800`;
+ };
+
+ // Photo dots
+ const dots = document.createElement("div");
+ dots.className = "card__dots";
+ p.imgs.forEach((_, di) => {
+ const dot = document.createElement("span");
+ dot.className = "dot" + (di === 0 ? " dot--active" : "");
+ dots.appendChild(dot);
+ });
+
+ // Card body
+ const body = document.createElement("div");
+ body.className = "card__body";
+
+ const titleRow = document.createElement("div");
+ titleRow.className = "title-row";
+ // Use textContent instead of innerHTML to avoid injection if data ever comes
+ // from an external source.
+ const nameEl = document.createElement("h2");
+ nameEl.className = "card__title";
+ nameEl.textContent = p.name;
+ const ageEl = document.createElement("span");
+ ageEl.className = "card__age";
+ ageEl.textContent = p.age;
+ titleRow.appendChild(nameEl);
+ titleRow.appendChild(ageEl);
+
+ const meta = document.createElement("div");
+ meta.className = "card__meta";
+ meta.textContent = `${p.title} • ${p.city}`;
+ const chips = document.createElement("div");
+ chips.className = "card__chips";
+ p.tags.forEach(t => {
+ const c = document.createElement("span");
+ c.className = "chip";
+ c.textContent = t;
+ chips.appendChild(c);
+ });
+
+ body.appendChild(titleRow);
+ body.appendChild(meta);
+ body.appendChild(chips);
+
+ card.appendChild(likeLabel);
+ card.appendChild(nopeLabel);
+ card.appendChild(superLabel);
+ card.appendChild(img);
+ card.appendChild(dots);
+ card.appendChild(body);
+
+ return card;
+}
+
+// -------------------
+// Deck rendering
+// -------------------
function renderDeck() {
+ // Cancel any in-flight dismissal timer so its callback can't attach duplicate
+ // listeners to the freshly-rendered deck.
+ clearTimeout(dismissTimerId);
+ dismissTimerId = null;
+
deckEl.setAttribute("aria-busy", "true");
deckEl.innerHTML = "";
profiles.forEach((p, idx) => {
- const card = document.createElement("article");
- card.className = "card";
-
- const img = document.createElement("img");
- img.className = "card__media";
- img.src = p.img;
- img.alt = `${p.name} — profile photo`;
-
- const body = document.createElement("div");
- body.className = "card__body";
-
- const titleRow = document.createElement("div");
- titleRow.className = "title-row";
- titleRow.innerHTML = `
-
${p.name}
- ${p.age}
- `;
-
- const meta = document.createElement("div");
- meta.className = "card__meta";
- meta.textContent = `${p.title} • ${p.city}`;
-
- const chips = document.createElement("div");
- chips.className = "card__chips";
- p.tags.forEach((t) => {
- const c = document.createElement("span");
- c.className = "chip";
- c.textContent = t;
- chips.appendChild(c);
- });
-
- body.appendChild(titleRow);
- body.appendChild(meta);
- body.appendChild(chips);
-
- card.appendChild(img);
- card.appendChild(body);
-
- deckEl.appendChild(card);
+ deckEl.appendChild(buildCard(p, idx, profiles.length));
});
deckEl.removeAttribute("aria-busy");
+ attachTopCardHandlers();
}
function resetDeck() {
@@ -132,17 +200,278 @@ function resetDeck() {
renderDeck();
}
-// Controls (intentionally not implemented)
-likeBtn.addEventListener("click", () => {
- console.log("Like clicked.");
-});
-nopeBtn.addEventListener("click", () => {
- console.log("Nope clicked.");
-});
-superLikeBtn.addEventListener("click", () => {
- console.log("Super Like clicked.");
-});
-shuffleBtn.addEventListener("click", resetDeck);
+// -------------------
+// Photo cycling (double-tap)
+// -------------------
+function cyclePhoto(card) {
+ const p = profiles[parseInt(card.dataset.profileIdx)];
+ const current = parseInt(card.dataset.photoIdx);
+ const next = (current + 1) % p.imgs.length;
+
+ card.dataset.photoIdx = next;
+ const img = card.querySelector(".card__media");
+ img.onerror = () => {
+ img.onerror = null;
+ img.src = `https://picsum.photos/seed/${p.id}-${next}/1200/800`;
+ };
+ img.src = p.imgs[next];
+ card.querySelectorAll(".dot").forEach((dot, i) => {
+ dot.classList.toggle("dot--active", i === next);
+ });
+}
+
+// -------------------
+// Backend API
+// -------------------
+const API_BASE = "http://localhost:3000";
+
+// -------------------
+// User identity (persisted in localStorage so push subscriptions are tied to this browser)
+// -------------------
+const USER_ID_KEY = "tinder_user_id";
+
+function getOrCreateUserId() {
+ let userId = localStorage.getItem(USER_ID_KEY);
+ if (!userId) {
+ userId = "u_" + Date.now().toString(36) + "_" + Math.random().toString(36).slice(2);
+ localStorage.setItem(USER_ID_KEY, userId);
+ }
+ return userId;
+}
+
+function recordSwipe(profile, action) {
+ fetch(`${API_BASE}/api/swipes`, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ profileId: profile.id,
+ profileName: profile.name,
+ action,
+ userId: getOrCreateUserId(),
+ }),
+ }).catch(err => console.warn("Swipe not recorded:", err.message));
+}
+
+// -------------------
+// Push notifications
+// -------------------
+function urlBase64ToUint8Array(base64String) {
+ const padding = "=".repeat((4 - (base64String.length % 4)) % 4);
+ const base64 = (base64String + padding).replace(/-/g, "+").replace(/_/g, "/");
+ const rawData = atob(base64);
+ const outputArray = new Uint8Array(rawData.length);
+ for (let i = 0; i < rawData.length; i++) {
+ outputArray[i] = rawData.charCodeAt(i);
+ }
+ return outputArray;
+}
+
+async function setupPushNotifications() {
+ if (!("serviceWorker" in navigator)) {
+ console.log("Push: service workers not supported in this browser.");
+ return;
+ }
+ if (!("PushManager" in window)) {
+ console.log("Push: Push API not supported in this browser.");
+ return;
+ }
+
+ try {
+ const registration = await navigator.serviceWorker.register("/sw.js");
+ console.log("Push: service worker registered.");
+
+ const permission = await Notification.requestPermission();
+ if (permission !== "granted") {
+ console.log("Push: notification permission denied.");
+ return;
+ }
+
+ // Fetch the server's VAPID public key
+ const resp = await fetch(`${API_BASE}/api/push/vapid-public-key`);
+ if (!resp.ok) throw new Error("Failed to fetch VAPID public key.");
+ const { publicKey } = await resp.json();
+
+ // Subscribe through the browser's Push Manager
+ const subscription = await registration.pushManager.subscribe({
+ userVisibleOnly: true,
+ applicationServerKey: urlBase64ToUint8Array(publicKey),
+ });
+
+ // Send subscription to backend
+ const userId = getOrCreateUserId();
+ await fetch(`${API_BASE}/api/push/subscribe`, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ userId, subscription }),
+ });
+
+ console.log("Push: subscribed successfully. Matches will trigger notifications!");
+ } catch (err) {
+ console.warn("Push: setup failed:", err.message);
+ }
+}
+
+// -------------------
+// Card dismissal
+// -------------------
+function dismissTop(direction) {
+ const card = deckEl.firstElementChild;
+ if (!card || card.classList.contains("card--leaving")) return;
+ card.classList.add("card--leaving");
+
+ const profile = profiles[parseInt(card.dataset.profileIdx)];
+ const action = direction === "super" ? "superlike" : direction;
+ recordSwipe(profile, action);
+
+ const likeLabel = card.querySelector(".swipe-label--like");
+ const nopeLabel = card.querySelector(".swipe-label--nope");
+ const superLabel = card.querySelector(".swipe-label--super");
+
+ let tx, ty, rot;
+ if (direction === "like") {
+ tx = "160%"; ty = "-10%"; rot = "30deg";
+ likeLabel.style.opacity = "1";
+ } else if (direction === "nope") {
+ tx = "-160%"; ty = "-10%"; rot = "-30deg";
+ nopeLabel.style.opacity = "1";
+ } else {
+ tx = "0"; ty = "-160%"; rot = "0deg";
+ superLabel.style.opacity = "1";
+ }
+
+ card.style.transition = "transform 380ms ease, opacity 380ms ease";
+ card.style.transform = `translate(${tx}, ${ty}) rotate(${rot})`;
+ card.style.opacity = "0";
+
+ dismissTimerId = setTimeout(() => {
+ dismissTimerId = null;
+ card.remove();
+ if (deckEl.children.length === 0) {
+ showEmptyState();
+ } else {
+ attachTopCardHandlers();
+ }
+ }, 380);
+}
+
+function showEmptyState() {
+ deckEl.innerHTML = `
+
+
👀
+
You've seen everyone!
+
Hit Shuffle to meet more people.
+
+ `;
+}
+
+// -------------------
+// Swipe + double-tap handlers
+// (attached only to the current top card)
+// -------------------
+function attachTopCardHandlers() {
+ const card = deckEl.firstElementChild;
+ if (!card || card.tagName !== "ARTICLE") return;
+
+ const likeLabel = card.querySelector(".swipe-label--like");
+ const nopeLabel = card.querySelector(".swipe-label--nope");
+ const superLabel = card.querySelector(".swipe-label--super");
+
+ const SWIPE_X = 80; // px to commit a left/right swipe
+ const SWIPE_Y = 90; // px to commit an upward swipe
+ const DOUBLE_TAP_MS = 300; // ms window for double-tap
+
+ let startX = 0, startY = 0, isDragging = false, lastTapTime = 0;
+
+ function resetLabels() {
+ likeLabel.style.opacity = "0";
+ nopeLabel.style.opacity = "0";
+ superLabel.style.opacity = "0";
+ }
+
+ card.addEventListener("pointerdown", e => {
+ startX = e.clientX;
+ startY = e.clientY;
+ isDragging = true;
+ card.setPointerCapture(e.pointerId);
+ card.style.transition = "none";
+ });
+
+ card.addEventListener("pointermove", e => {
+ if (!isDragging) return;
+ const dx = e.clientX - startX;
+ const dy = e.clientY - startY;
+ const rot = dx * 0.07; // subtle rotation proportional to horizontal drag
+
+ card.style.transform = `translate(${dx}px, ${dy}px) rotate(${rot}deg)`;
+
+ // Fade labels in relative to drag distance
+ if (dy < -40 && Math.abs(dy) > Math.abs(dx)) {
+ superLabel.style.opacity = Math.min(1, (-dy - 40) / 70).toFixed(2);
+ likeLabel.style.opacity = "0";
+ nopeLabel.style.opacity = "0";
+ } else if (dx > 20) {
+ likeLabel.style.opacity = Math.min(1, (dx - 20) / 60).toFixed(2);
+ nopeLabel.style.opacity = "0";
+ superLabel.style.opacity = "0";
+ } else if (dx < -20) {
+ nopeLabel.style.opacity = Math.min(1, (-dx - 20) / 60).toFixed(2);
+ likeLabel.style.opacity = "0";
+ superLabel.style.opacity = "0";
+ } else {
+ resetLabels();
+ }
+ });
+
+ card.addEventListener("pointerup", e => {
+ if (!isDragging) return;
+ isDragging = false;
+ card.style.transition = "";
+
+ const dx = e.clientX - startX;
+ const dy = e.clientY - startY;
+ const dist = Math.hypot(dx, dy);
+ const now = Date.now();
+
+ // Double-tap: minimal movement + second tap within window
+ if (dist < 12 && now - lastTapTime < DOUBLE_TAP_MS) {
+ lastTapTime = 0;
+ resetLabels();
+ card.style.transform = "";
+ cyclePhoto(card);
+ return;
+ }
+ lastTapTime = now;
+
+ // Decide swipe direction by threshold
+ if (dy < -SWIPE_Y && Math.abs(dy) > Math.abs(dx)) {
+ dismissTop("super");
+ } else if (dx > SWIPE_X) {
+ dismissTop("like");
+ } else if (dx < -SWIPE_X) {
+ dismissTop("nope");
+ } else {
+ // Didn't cross threshold — snap back
+ card.style.transform = "";
+ resetLabels();
+ }
+ });
+
+ card.addEventListener("pointercancel", () => {
+ isDragging = false;
+ card.style.transition = "";
+ card.style.transform = "";
+ resetLabels();
+ });
+}
+
+// -------------------
+// Action buttons
+// -------------------
+likeBtn.addEventListener("click", () => dismissTop("like"));
+nopeBtn.addEventListener("click", () => dismissTop("nope"));
+superLikeBtn.addEventListener("click", () => dismissTop("super"));
+shuffleBtn.addEventListener("click", resetDeck);
// Boot
resetDeck();
+setupPushNotifications();
diff --git a/backend/.gitignore b/backend/.gitignore
new file mode 100644
index 00000000..3f81d1ce
--- /dev/null
+++ b/backend/.gitignore
@@ -0,0 +1,5 @@
+node_modules/
+*.db
+*.db-shm
+*.db-wal
+vapid_keys.json
diff --git a/backend/db.js b/backend/db.js
new file mode 100644
index 00000000..b82c91d0
--- /dev/null
+++ b/backend/db.js
@@ -0,0 +1,26 @@
+'use strict';
+
+const { DatabaseSync } = require('node:sqlite');
+const path = require('path');
+
+const DB_PATH = process.env.DB_PATH || path.join(__dirname, 'swipes.db');
+
+const db = new DatabaseSync(DB_PATH);
+
+db.exec(`
+ CREATE TABLE IF NOT EXISTS swipes (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ profile_id TEXT NOT NULL,
+ profile_name TEXT NOT NULL,
+ action TEXT NOT NULL CHECK(action IN ('like', 'nope', 'superlike')),
+ swiped_at TEXT NOT NULL
+ );
+
+ CREATE TABLE IF NOT EXISTS push_subscriptions (
+ user_id TEXT PRIMARY KEY,
+ subscription TEXT NOT NULL,
+ created_at TEXT NOT NULL
+ );
+`);
+
+module.exports = db;
diff --git a/backend/package-lock.json b/backend/package-lock.json
new file mode 100644
index 00000000..9fb82f5b
--- /dev/null
+++ b/backend/package-lock.json
@@ -0,0 +1,997 @@
+{
+ "name": "snow-day-backend",
+ "version": "1.0.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "snow-day-backend",
+ "version": "1.0.0",
+ "dependencies": {
+ "cors": "^2.8.5",
+ "express": "^4.19.2",
+ "web-push": "^3.6.7"
+ }
+ },
+ "node_modules/accepts": {
+ "version": "1.3.8",
+ "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
+ "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
+ "license": "MIT",
+ "dependencies": {
+ "mime-types": "~2.1.34",
+ "negotiator": "0.6.3"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/agent-base": {
+ "version": "7.1.4",
+ "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz",
+ "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 14"
+ }
+ },
+ "node_modules/array-flatten": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+ "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
+ "license": "MIT"
+ },
+ "node_modules/asn1.js": {
+ "version": "5.4.1",
+ "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-5.4.1.tgz",
+ "integrity": "sha512-+I//4cYPccV8LdmBLiX8CYvf9Sp3vQsrqu2QNXRcrbiWvcx/UdlFiqUJJzxRQxgsZmvhXhn4cSKeSmoFjVdupA==",
+ "license": "MIT",
+ "dependencies": {
+ "bn.js": "^4.0.0",
+ "inherits": "^2.0.1",
+ "minimalistic-assert": "^1.0.0",
+ "safer-buffer": "^2.1.0"
+ }
+ },
+ "node_modules/bn.js": {
+ "version": "4.12.3",
+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.3.tgz",
+ "integrity": "sha512-fGTi3gxV/23FTYdAoUtLYp6qySe2KE3teyZitipKNRuVYcBkoP/bB3guXN/XVKUe9mxCHXnc9C4ocyz8OmgN0g==",
+ "license": "MIT"
+ },
+ "node_modules/body-parser": {
+ "version": "1.20.4",
+ "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.4.tgz",
+ "integrity": "sha512-ZTgYYLMOXY9qKU/57FAo8F+HA2dGX7bqGc71txDRC1rS4frdFI5R7NhluHxH6M0YItAP0sHB4uqAOcYKxO6uGA==",
+ "license": "MIT",
+ "dependencies": {
+ "bytes": "~3.1.2",
+ "content-type": "~1.0.5",
+ "debug": "2.6.9",
+ "depd": "2.0.0",
+ "destroy": "~1.2.0",
+ "http-errors": "~2.0.1",
+ "iconv-lite": "~0.4.24",
+ "on-finished": "~2.4.1",
+ "qs": "~6.14.0",
+ "raw-body": "~2.5.3",
+ "type-is": "~1.6.18",
+ "unpipe": "~1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.8",
+ "npm": "1.2.8000 || >= 1.4.16"
+ }
+ },
+ "node_modules/buffer-equal-constant-time": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
+ "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==",
+ "license": "BSD-3-Clause"
+ },
+ "node_modules/bytes": {
+ "version": "3.1.2",
+ "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
+ "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/call-bind-apply-helpers": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
+ "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0",
+ "function-bind": "^1.1.2"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/call-bound": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
+ "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bind-apply-helpers": "^1.0.2",
+ "get-intrinsic": "^1.3.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/content-disposition": {
+ "version": "0.5.4",
+ "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
+ "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
+ "license": "MIT",
+ "dependencies": {
+ "safe-buffer": "5.2.1"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/content-type": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
+ "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/cookie": {
+ "version": "0.7.2",
+ "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
+ "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/cookie-signature": {
+ "version": "1.0.7",
+ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz",
+ "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==",
+ "license": "MIT"
+ },
+ "node_modules/cors": {
+ "version": "2.8.6",
+ "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz",
+ "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==",
+ "license": "MIT",
+ "dependencies": {
+ "object-assign": "^4",
+ "vary": "^1"
+ },
+ "engines": {
+ "node": ">= 0.10"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
+ "node_modules/debug": {
+ "version": "2.6.9",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
+ "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
+ "license": "MIT",
+ "dependencies": {
+ "ms": "2.0.0"
+ }
+ },
+ "node_modules/depd": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
+ "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/destroy": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
+ "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8",
+ "npm": "1.2.8000 || >= 1.4.16"
+ }
+ },
+ "node_modules/dunder-proto": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
+ "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bind-apply-helpers": "^1.0.1",
+ "es-errors": "^1.3.0",
+ "gopd": "^1.2.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/ecdsa-sig-formatter": {
+ "version": "1.0.11",
+ "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
+ "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==",
+ "license": "Apache-2.0",
+ "dependencies": {
+ "safe-buffer": "^5.0.1"
+ }
+ },
+ "node_modules/ee-first": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
+ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
+ "license": "MIT"
+ },
+ "node_modules/encodeurl": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
+ "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/es-define-property": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
+ "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/es-errors": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
+ "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/es-object-atoms": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
+ "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/escape-html": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
+ "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
+ "license": "MIT"
+ },
+ "node_modules/etag": {
+ "version": "1.8.1",
+ "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
+ "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/express": {
+ "version": "4.22.1",
+ "resolved": "https://registry.npmjs.org/express/-/express-4.22.1.tgz",
+ "integrity": "sha512-F2X8g9P1X7uCPZMA3MVf9wcTqlyNp7IhH5qPCI0izhaOIYXaW9L535tGA3qmjRzpH+bZczqq7hVKxTR4NWnu+g==",
+ "license": "MIT",
+ "dependencies": {
+ "accepts": "~1.3.8",
+ "array-flatten": "1.1.1",
+ "body-parser": "~1.20.3",
+ "content-disposition": "~0.5.4",
+ "content-type": "~1.0.4",
+ "cookie": "~0.7.1",
+ "cookie-signature": "~1.0.6",
+ "debug": "2.6.9",
+ "depd": "2.0.0",
+ "encodeurl": "~2.0.0",
+ "escape-html": "~1.0.3",
+ "etag": "~1.8.1",
+ "finalhandler": "~1.3.1",
+ "fresh": "~0.5.2",
+ "http-errors": "~2.0.0",
+ "merge-descriptors": "1.0.3",
+ "methods": "~1.1.2",
+ "on-finished": "~2.4.1",
+ "parseurl": "~1.3.3",
+ "path-to-regexp": "~0.1.12",
+ "proxy-addr": "~2.0.7",
+ "qs": "~6.14.0",
+ "range-parser": "~1.2.1",
+ "safe-buffer": "5.2.1",
+ "send": "~0.19.0",
+ "serve-static": "~1.16.2",
+ "setprototypeof": "1.2.0",
+ "statuses": "~2.0.1",
+ "type-is": "~1.6.18",
+ "utils-merge": "1.0.1",
+ "vary": "~1.1.2"
+ },
+ "engines": {
+ "node": ">= 0.10.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
+ "node_modules/finalhandler": {
+ "version": "1.3.2",
+ "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz",
+ "integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==",
+ "license": "MIT",
+ "dependencies": {
+ "debug": "2.6.9",
+ "encodeurl": "~2.0.0",
+ "escape-html": "~1.0.3",
+ "on-finished": "~2.4.1",
+ "parseurl": "~1.3.3",
+ "statuses": "~2.0.2",
+ "unpipe": "~1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/forwarded": {
+ "version": "0.2.0",
+ "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
+ "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/fresh": {
+ "version": "0.5.2",
+ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
+ "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/function-bind": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
+ "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/get-intrinsic": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
+ "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bind-apply-helpers": "^1.0.2",
+ "es-define-property": "^1.0.1",
+ "es-errors": "^1.3.0",
+ "es-object-atoms": "^1.1.1",
+ "function-bind": "^1.1.2",
+ "get-proto": "^1.0.1",
+ "gopd": "^1.2.0",
+ "has-symbols": "^1.1.0",
+ "hasown": "^2.0.2",
+ "math-intrinsics": "^1.1.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/get-proto": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
+ "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
+ "license": "MIT",
+ "dependencies": {
+ "dunder-proto": "^1.0.1",
+ "es-object-atoms": "^1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/gopd": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
+ "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/has-symbols": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
+ "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/hasown": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
+ "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
+ "license": "MIT",
+ "dependencies": {
+ "function-bind": "^1.1.2"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/http_ece": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/http_ece/-/http_ece-1.2.0.tgz",
+ "integrity": "sha512-JrF8SSLVmcvc5NducxgyOrKXe3EsyHMgBFgSaIUGmArKe+rwr0uphRkRXvwiom3I+fpIfoItveHrfudL8/rxuA==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=16"
+ }
+ },
+ "node_modules/http-errors": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
+ "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
+ "license": "MIT",
+ "dependencies": {
+ "depd": "~2.0.0",
+ "inherits": "~2.0.4",
+ "setprototypeof": "~1.2.0",
+ "statuses": "~2.0.2",
+ "toidentifier": "~1.0.1"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
+ "node_modules/https-proxy-agent": {
+ "version": "7.0.6",
+ "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz",
+ "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==",
+ "license": "MIT",
+ "dependencies": {
+ "agent-base": "^7.1.2",
+ "debug": "4"
+ },
+ "engines": {
+ "node": ">= 14"
+ }
+ },
+ "node_modules/https-proxy-agent/node_modules/debug": {
+ "version": "4.4.3",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
+ "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
+ "license": "MIT",
+ "dependencies": {
+ "ms": "^2.1.3"
+ },
+ "engines": {
+ "node": ">=6.0"
+ },
+ "peerDependenciesMeta": {
+ "supports-color": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/https-proxy-agent/node_modules/ms": {
+ "version": "2.1.3",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
+ "license": "MIT"
+ },
+ "node_modules/iconv-lite": {
+ "version": "0.4.24",
+ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
+ "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
+ "license": "MIT",
+ "dependencies": {
+ "safer-buffer": ">= 2.1.2 < 3"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/inherits": {
+ "version": "2.0.4",
+ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
+ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
+ "license": "ISC"
+ },
+ "node_modules/ipaddr.js": {
+ "version": "1.9.1",
+ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
+ "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.10"
+ }
+ },
+ "node_modules/jwa": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz",
+ "integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==",
+ "license": "MIT",
+ "dependencies": {
+ "buffer-equal-constant-time": "^1.0.1",
+ "ecdsa-sig-formatter": "1.0.11",
+ "safe-buffer": "^5.0.1"
+ }
+ },
+ "node_modules/jws": {
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz",
+ "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==",
+ "license": "MIT",
+ "dependencies": {
+ "jwa": "^2.0.1",
+ "safe-buffer": "^5.0.1"
+ }
+ },
+ "node_modules/math-intrinsics": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
+ "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/media-typer": {
+ "version": "0.3.0",
+ "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
+ "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/merge-descriptors": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
+ "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==",
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/sponsors/sindresorhus"
+ }
+ },
+ "node_modules/methods": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
+ "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/mime": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
+ "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
+ "license": "MIT",
+ "bin": {
+ "mime": "cli.js"
+ },
+ "engines": {
+ "node": ">=4"
+ }
+ },
+ "node_modules/mime-db": {
+ "version": "1.52.0",
+ "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
+ "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/mime-types": {
+ "version": "2.1.35",
+ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
+ "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
+ "license": "MIT",
+ "dependencies": {
+ "mime-db": "1.52.0"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/minimalistic-assert": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz",
+ "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==",
+ "license": "ISC"
+ },
+ "node_modules/minimist": {
+ "version": "1.2.8",
+ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
+ "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/ms": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
+ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
+ "license": "MIT"
+ },
+ "node_modules/negotiator": {
+ "version": "0.6.3",
+ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
+ "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/object-assign": {
+ "version": "4.1.1",
+ "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
+ "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/object-inspect": {
+ "version": "1.13.4",
+ "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
+ "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/on-finished": {
+ "version": "2.4.1",
+ "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
+ "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
+ "license": "MIT",
+ "dependencies": {
+ "ee-first": "1.1.1"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/parseurl": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
+ "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/path-to-regexp": {
+ "version": "0.1.12",
+ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz",
+ "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==",
+ "license": "MIT"
+ },
+ "node_modules/proxy-addr": {
+ "version": "2.0.7",
+ "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
+ "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
+ "license": "MIT",
+ "dependencies": {
+ "forwarded": "0.2.0",
+ "ipaddr.js": "1.9.1"
+ },
+ "engines": {
+ "node": ">= 0.10"
+ }
+ },
+ "node_modules/qs": {
+ "version": "6.14.2",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.2.tgz",
+ "integrity": "sha512-V/yCWTTF7VJ9hIh18Ugr2zhJMP01MY7c5kh4J870L7imm6/DIzBsNLTXzMwUA3yZ5b/KBqLx8Kp3uRvd7xSe3Q==",
+ "license": "BSD-3-Clause",
+ "dependencies": {
+ "side-channel": "^1.1.0"
+ },
+ "engines": {
+ "node": ">=0.6"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/range-parser": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
+ "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/raw-body": {
+ "version": "2.5.3",
+ "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz",
+ "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==",
+ "license": "MIT",
+ "dependencies": {
+ "bytes": "~3.1.2",
+ "http-errors": "~2.0.1",
+ "iconv-lite": "~0.4.24",
+ "unpipe": "~1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/safe-buffer": {
+ "version": "5.2.1",
+ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
+ "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/feross"
+ },
+ {
+ "type": "patreon",
+ "url": "https://www.patreon.com/feross"
+ },
+ {
+ "type": "consulting",
+ "url": "https://feross.org/support"
+ }
+ ],
+ "license": "MIT"
+ },
+ "node_modules/safer-buffer": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
+ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
+ "license": "MIT"
+ },
+ "node_modules/send": {
+ "version": "0.19.2",
+ "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz",
+ "integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==",
+ "license": "MIT",
+ "dependencies": {
+ "debug": "2.6.9",
+ "depd": "2.0.0",
+ "destroy": "1.2.0",
+ "encodeurl": "~2.0.0",
+ "escape-html": "~1.0.3",
+ "etag": "~1.8.1",
+ "fresh": "~0.5.2",
+ "http-errors": "~2.0.1",
+ "mime": "1.6.0",
+ "ms": "2.1.3",
+ "on-finished": "~2.4.1",
+ "range-parser": "~1.2.1",
+ "statuses": "~2.0.2"
+ },
+ "engines": {
+ "node": ">= 0.8.0"
+ }
+ },
+ "node_modules/send/node_modules/ms": {
+ "version": "2.1.3",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
+ "license": "MIT"
+ },
+ "node_modules/serve-static": {
+ "version": "1.16.3",
+ "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz",
+ "integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==",
+ "license": "MIT",
+ "dependencies": {
+ "encodeurl": "~2.0.0",
+ "escape-html": "~1.0.3",
+ "parseurl": "~1.3.3",
+ "send": "~0.19.1"
+ },
+ "engines": {
+ "node": ">= 0.8.0"
+ }
+ },
+ "node_modules/setprototypeof": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
+ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
+ "license": "ISC"
+ },
+ "node_modules/side-channel": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz",
+ "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0",
+ "object-inspect": "^1.13.3",
+ "side-channel-list": "^1.0.0",
+ "side-channel-map": "^1.0.1",
+ "side-channel-weakmap": "^1.0.2"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/side-channel-list": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz",
+ "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0",
+ "object-inspect": "^1.13.3"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/side-channel-map": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
+ "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bound": "^1.0.2",
+ "es-errors": "^1.3.0",
+ "get-intrinsic": "^1.2.5",
+ "object-inspect": "^1.13.3"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/side-channel-weakmap": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
+ "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bound": "^1.0.2",
+ "es-errors": "^1.3.0",
+ "get-intrinsic": "^1.2.5",
+ "object-inspect": "^1.13.3",
+ "side-channel-map": "^1.0.1"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/statuses": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
+ "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/toidentifier": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
+ "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=0.6"
+ }
+ },
+ "node_modules/type-is": {
+ "version": "1.6.18",
+ "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
+ "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
+ "license": "MIT",
+ "dependencies": {
+ "media-typer": "0.3.0",
+ "mime-types": "~2.1.24"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/unpipe": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
+ "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/utils-merge": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
+ "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4.0"
+ }
+ },
+ "node_modules/vary": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
+ "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/web-push": {
+ "version": "3.6.7",
+ "resolved": "https://registry.npmjs.org/web-push/-/web-push-3.6.7.tgz",
+ "integrity": "sha512-OpiIUe8cuGjrj3mMBFWY+e4MMIkW3SVT+7vEIjvD9kejGUypv8GPDf84JdPWskK8zMRIJ6xYGm+Kxr8YkPyA0A==",
+ "license": "MPL-2.0",
+ "dependencies": {
+ "asn1.js": "^5.3.0",
+ "http_ece": "1.2.0",
+ "https-proxy-agent": "^7.0.0",
+ "jws": "^4.0.0",
+ "minimist": "^1.2.5"
+ },
+ "bin": {
+ "web-push": "src/cli.js"
+ },
+ "engines": {
+ "node": ">= 16"
+ }
+ }
+ }
+}
diff --git a/backend/package.json b/backend/package.json
new file mode 100644
index 00000000..ac343a81
--- /dev/null
+++ b/backend/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "snow-day-backend",
+ "version": "1.0.0",
+ "description": "Swipe action API for the Tinder clone snow-day activity",
+ "main": "server.js",
+ "scripts": {
+ "start": "node --experimental-sqlite server.js",
+ "dev": "node --experimental-sqlite --watch server.js",
+ "test": "node --experimental-sqlite --test tests/*.test.js"
+ },
+ "dependencies": {
+ "cors": "^2.8.5",
+ "express": "^4.19.2",
+ "web-push": "^3.6.7"
+ }
+}
diff --git a/backend/routes/push.js b/backend/routes/push.js
new file mode 100644
index 00000000..ebf0c952
--- /dev/null
+++ b/backend/routes/push.js
@@ -0,0 +1,50 @@
+'use strict';
+
+const express = require('express');
+const db = require('../db');
+const { vapidKeys } = require('../vapid');
+
+const router = express.Router();
+
+// GET /api/push/vapid-public-key — return the VAPID public key for client subscription
+router.get('/vapid-public-key', (_req, res) => {
+ res.json({ publicKey: vapidKeys.publicKey });
+});
+
+// POST /api/push/subscribe — store a push subscription for a user
+router.post('/subscribe', (req, res) => {
+ const { userId, subscription } = req.body;
+
+ if (!userId || typeof userId !== 'string' || userId.trim() === '') {
+ return res.status(400).json({ error: 'userId is required and must be a non-empty string.' });
+ }
+ if (!subscription || typeof subscription !== 'object' || !subscription.endpoint) {
+ return res.status(400).json({ error: 'subscription must be a valid push subscription object with an endpoint.' });
+ }
+
+ const cleanUserId = userId.trim();
+ const subscriptionJson = JSON.stringify(subscription);
+ const createdAt = new Date().toISOString();
+
+ db.prepare(`
+ INSERT INTO push_subscriptions (user_id, subscription, created_at)
+ VALUES (?, ?, ?)
+ ON CONFLICT(user_id) DO UPDATE SET subscription = excluded.subscription
+ `).run(cleanUserId, subscriptionJson, createdAt);
+
+ return res.status(201).json({ message: 'Subscribed successfully.' });
+});
+
+// DELETE /api/push/subscribe — remove a push subscription
+router.delete('/subscribe', (req, res) => {
+ const { userId } = req.body;
+
+ if (!userId || typeof userId !== 'string' || userId.trim() === '') {
+ return res.status(400).json({ error: 'userId is required and must be a non-empty string.' });
+ }
+
+ db.prepare('DELETE FROM push_subscriptions WHERE user_id = ?').run(userId.trim());
+ return res.json({ message: 'Unsubscribed successfully.' });
+});
+
+module.exports = router;
diff --git a/backend/routes/swipes.js b/backend/routes/swipes.js
new file mode 100644
index 00000000..b6a44abf
--- /dev/null
+++ b/backend/routes/swipes.js
@@ -0,0 +1,116 @@
+'use strict';
+
+const express = require('express');
+const db = require('../db');
+const { webpush } = require('../vapid');
+
+const router = express.Router();
+
+const VALID_ACTIONS = new Set(['like', 'nope', 'superlike']);
+
+// Match probability per action
+const MATCH_CHANCE = { like: 0.3, superlike: 0.6 };
+
+async function sendMatchNotification(userId, profileName) {
+ const row = db.prepare(
+ 'SELECT subscription FROM push_subscriptions WHERE user_id = ?'
+ ).get(userId);
+
+ if (!row) return;
+
+ const payload = JSON.stringify({
+ title: "It's a Match! 🎉",
+ body: `You and ${profileName} liked each other!`,
+ url: '/',
+ });
+
+ try {
+ await webpush.sendNotification(JSON.parse(row.subscription), payload);
+ } catch (err) {
+ // Subscription may be expired or invalid — remove it
+ if (err.statusCode === 404 || err.statusCode === 410) {
+ db.prepare('DELETE FROM push_subscriptions WHERE user_id = ?').run(userId);
+ } else {
+ console.error('Push notification error:', err.message);
+ }
+ }
+}
+
+// POST /api/swipes — record a swipe action
+router.post('/', async (req, res) => {
+ const { profileId, profileName, action, userId } = req.body;
+
+ if (!profileId || typeof profileId !== 'string' || profileId.trim() === '') {
+ return res.status(400).json({ error: 'profileId is required and must be a non-empty string.' });
+ }
+ if (!profileName || typeof profileName !== 'string' || profileName.trim() === '') {
+ return res.status(400).json({ error: 'profileName is required and must be a non-empty string.' });
+ }
+ if (!action || !VALID_ACTIONS.has(action)) {
+ return res.status(400).json({ error: `action must be one of: ${[...VALID_ACTIONS].join(', ')}.` });
+ }
+
+ const cleanId = profileId.trim();
+ const cleanName = profileName.trim();
+ const cleanUserId = userId && typeof userId === 'string' ? userId.trim() : null;
+ const swipedAt = new Date().toISOString();
+
+ const stmt = db.prepare(
+ 'INSERT INTO swipes (profile_id, profile_name, action, swiped_at) VALUES (?, ?, ?, ?)'
+ );
+ const result = stmt.run(cleanId, cleanName, action, swipedAt);
+
+ // Simulate match for like/superlike and send push notification if subscribed
+ const chance = MATCH_CHANCE[action];
+ const isMatch = chance !== undefined && Math.random() < chance;
+
+ if (isMatch && cleanUserId) {
+ // Fire-and-forget — don't block the response
+ sendMatchNotification(cleanUserId, cleanName).catch(err =>
+ console.error('Match notification failed:', err.message)
+ );
+ }
+
+ return res.status(201).json({
+ id: result.lastInsertRowid,
+ profileId: cleanId,
+ profileName: cleanName,
+ action,
+ swipedAt,
+ matched: isMatch,
+ });
+});
+
+// GET /api/swipes — return all recorded swipes (newest first)
+router.get('/', (_req, res) => {
+ const rows = db.prepare(
+ `SELECT
+ id,
+ profile_id AS profileId,
+ profile_name AS profileName,
+ action,
+ swiped_at AS swipedAt
+ FROM swipes
+ ORDER BY id DESC`
+ ).all();
+
+ return res.json({ swipes: rows });
+});
+
+// GET /api/swipes/stats — return counts grouped by action
+router.get('/stats', (_req, res) => {
+ const rows = db.prepare(
+ 'SELECT action, COUNT(*) AS count FROM swipes GROUP BY action'
+ ).all();
+
+ const stats = { like: 0, nope: 0, superlike: 0, total: 0 };
+
+ for (const row of rows) {
+ stats[row.action] = Number(row.count);
+ stats.total += Number(row.count);
+ }
+
+ return res.json(stats);
+});
+
+module.exports = router;
diff --git a/backend/server.js b/backend/server.js
new file mode 100644
index 00000000..d2f42fe5
--- /dev/null
+++ b/backend/server.js
@@ -0,0 +1,43 @@
+'use strict';
+
+const path = require('path');
+const express = require('express');
+const cors = require('cors');
+const swipesRouter = require('./routes/swipes');
+const pushRouter = require('./routes/push');
+
+const PORT = process.env.PORT || 3000;
+
+const app = express();
+
+app.use(cors());
+app.use(express.json());
+
+// Serve frontend static files from the project root
+app.use(express.static(path.join(__dirname, '..')));
+
+// Health check
+app.get('/health', (_req, res) => res.json({ status: 'ok' }));
+
+// Swipe routes
+app.use('/api/swipes', swipesRouter);
+
+// Push notification routes
+app.use('/api/push', pushRouter);
+
+// 404 handler
+app.use((_req, res) => res.status(404).json({ error: 'Not found.' }));
+
+// Global error handler
+app.use((err, _req, res, _next) => {
+ console.error(err);
+ res.status(500).json({ error: 'Internal server error.' });
+});
+
+if (require.main === module) {
+ app.listen(PORT, () => {
+ console.log(`Snow-day backend running on http://localhost:${PORT}`);
+ });
+}
+
+module.exports = app;
diff --git a/backend/tests/push.test.js b/backend/tests/push.test.js
new file mode 100644
index 00000000..4865f6b0
--- /dev/null
+++ b/backend/tests/push.test.js
@@ -0,0 +1,176 @@
+'use strict';
+
+const { describe, it, before, after, beforeEach } = require('node:test');
+const assert = require('node:assert/strict');
+const http = require('node:http');
+
+// Use in-memory DB
+process.env.DB_PATH = ':memory:';
+
+const app = require('../server');
+
+// Helpers (same as swipes.test.js)
+let server;
+let baseUrl;
+
+function request(method, path, body) {
+ return new Promise((resolve, reject) => {
+ const url = new URL(path, baseUrl);
+ const payload = body ? JSON.stringify(body) : undefined;
+ const opts = {
+ method,
+ hostname: url.hostname,
+ port: url.port,
+ path: url.pathname,
+ headers: {
+ 'Content-Type': 'application/json',
+ ...(payload ? { 'Content-Length': Buffer.byteLength(payload) } : {}),
+ },
+ };
+
+ const req = http.request(opts, (res) => {
+ let data = '';
+ res.on('data', (chunk) => { data += chunk; });
+ res.on('end', () => {
+ try {
+ resolve({ status: res.statusCode, body: JSON.parse(data) });
+ } catch (e) {
+ reject(e);
+ }
+ });
+ });
+ req.on('error', reject);
+ if (payload) req.write(payload);
+ req.end();
+ });
+}
+
+// Lifecycle
+before(() => new Promise((resolve) => {
+ server = app.listen(0, () => {
+ baseUrl = `http://localhost:${server.address().port}`;
+ resolve();
+ });
+}));
+
+after(() => new Promise((resolve) => {
+ server.closeAllConnections();
+ server.close(resolve);
+}));
+
+const db = require('../db');
+beforeEach(() => {
+ db.exec('DELETE FROM swipes');
+ db.exec('DELETE FROM push_subscriptions');
+});
+
+// GET /api/push/vapid-public-key
+describe('GET /api/push/vapid-public-key', () => {
+ it('returns 200 with publicKey string', async () => {
+ const res = await request('GET', '/api/push/vapid-public-key');
+ assert.equal(res.status, 200);
+ assert.ok(res.body.publicKey);
+ assert.equal(typeof res.body.publicKey, 'string');
+ assert.ok(res.body.publicKey.length > 20);
+ });
+});
+
+// POST /api/push/subscribe
+describe('POST /api/push/subscribe', () => {
+ it('records valid subscription and returns 201', async () => {
+ const sub = {
+ endpoint: 'https://example.com/sub',
+ keys: { p256dh: 'key1', auth: 'key2' }
+ };
+ const res = await request('POST', '/api/push/subscribe', {
+ userId: 'test_user',
+ subscription: sub
+ });
+ assert.equal(res.status, 201);
+ assert.equal(res.body.message, 'Subscribed successfully.');
+
+ // Verify DB insert
+ const row = db.prepare('SELECT * FROM push_subscriptions WHERE user_id = ?').get('test_user');
+ assert.equal(row.user_id, 'test_user');
+ assert.ok(row.subscription);
+ assert.ok(JSON.parse(row.subscription).endpoint);
+ });
+
+ it('upserts existing user (updates subscription)', async () => {
+ const sub1 = { endpoint: 'old' };
+ await request('POST', '/api/push/subscribe', {
+ userId: 'test_user',
+ subscription: sub1
+ });
+ const sub2 = { endpoint: 'new' };
+ await request('POST', '/api/push/subscribe', {
+ userId: 'test_user',
+ subscription: sub2
+ });
+
+ const row = db.prepare('SELECT subscription FROM push_subscriptions WHERE user_id = ?').get('test_user');
+ assert.equal(JSON.parse(row.subscription).endpoint, 'new');
+ });
+
+ it('returns 400 for missing userId', async () => {
+ const res = await request('POST', '/api/push/subscribe', {
+ subscription: { endpoint: 'test' }
+ });
+ assert.equal(res.status, 400);
+ assert.ok(res.body.error);
+ });
+
+ it('returns 400 for blank userId', async () => {
+ const res = await request('POST', '/api/push/subscribe', {
+ userId: ' ',
+ subscription: { endpoint: 'test' }
+ });
+ assert.equal(res.status, 400);
+ assert.ok(res.body.error);
+ });
+
+ it('returns 400 for missing endpoint in subscription', async () => {
+ const res = await request('POST', '/api/push/subscribe', {
+ userId: 'test_user',
+ subscription: {}
+ });
+ assert.equal(res.status, 400);
+ assert.ok(res.body.error);
+ });
+
+ it('trims userId whitespace', async () => {
+ const res = await request('POST', '/api/push/subscribe', {
+ userId: ' test_user ',
+ subscription: { endpoint: 'test' }
+ });
+ assert.equal(res.status, 201);
+
+ const row = db.prepare('SELECT user_id FROM push_subscriptions WHERE user_id = ?').get('test_user');
+ assert.ok(row);
+ });
+});
+
+// DELETE /api/push/subscribe
+describe('DELETE /api/push/subscribe', () => {
+ it('removes subscription and returns success', async () => {
+ await request('POST', '/api/push/subscribe', {
+ userId: 'test_user',
+ subscription: { endpoint: 'test' }
+ });
+
+ const res = await request('DELETE', '/api/push/subscribe', {
+ userId: 'test_user'
+ });
+ assert.equal(res.status, 200);
+ assert.equal(res.body.message, 'Unsubscribed successfully.');
+
+ const row = db.prepare('SELECT * FROM push_subscriptions WHERE user_id = ?').get('test_user');
+ assert.equal(row, undefined);
+ });
+
+ it('returns 400 for missing userId', async () => {
+ const res = await request('DELETE', '/api/push/subscribe', {});
+ assert.equal(res.status, 400);
+ assert.ok(res.body.error);
+ });
+});
diff --git a/backend/tests/swipes.test.js b/backend/tests/swipes.test.js
new file mode 100644
index 00000000..7210e2f3
--- /dev/null
+++ b/backend/tests/swipes.test.js
@@ -0,0 +1,241 @@
+'use strict';
+
+const { describe, it, before, after, beforeEach } = require('node:test');
+const assert = require('node:assert/strict');
+const http = require('node:http');
+
+// Use an in-memory database for tests
+process.env.DB_PATH = ':memory:';
+
+const app = require('../server');
+
+// ---------------------------------------------------------------------------
+// Helpers
+// ---------------------------------------------------------------------------
+
+let server;
+let baseUrl;
+
+function request(method, path, body) {
+ return new Promise((resolve, reject) => {
+ const url = new URL(path, baseUrl);
+ const payload = body ? JSON.stringify(body) : undefined;
+ const opts = {
+ method,
+ hostname: url.hostname,
+ port: url.port,
+ path: url.pathname,
+ headers: {
+ 'Content-Type': 'application/json',
+ ...(payload ? { 'Content-Length': Buffer.byteLength(payload) } : {}),
+ },
+ };
+
+ const req = http.request(opts, (res) => {
+ let data = '';
+ res.on('data', (chunk) => { data += chunk; });
+ res.on('end', () => {
+ try {
+ resolve({ status: res.statusCode, body: JSON.parse(data) });
+ } catch (e) {
+ reject(e);
+ }
+ });
+ });
+ req.on('error', reject);
+ if (payload) req.write(payload);
+ req.end();
+ });
+}
+
+// ---------------------------------------------------------------------------
+// Lifecycle
+// ---------------------------------------------------------------------------
+
+before(() => new Promise((resolve) => {
+ server = app.listen(0, () => {
+ baseUrl = `http://localhost:${server.address().port}`;
+ resolve();
+ });
+}));
+
+after(() => new Promise((resolve) => {
+ server.closeAllConnections();
+ server.close(resolve);
+}));
+
+// Clear table before each test for isolation
+const db = require('../db');
+beforeEach(() => db.exec('DELETE FROM swipes'));
+
+// ---------------------------------------------------------------------------
+// Health check
+// ---------------------------------------------------------------------------
+
+describe('GET /health', () => {
+ it('returns 200 ok', async () => {
+ const res = await request('GET', '/health');
+ assert.equal(res.status, 200);
+ assert.equal(res.body.status, 'ok');
+ });
+});
+
+// ---------------------------------------------------------------------------
+// POST /api/swipes
+// ---------------------------------------------------------------------------
+
+describe('POST /api/swipes', () => {
+ it('records a like and returns 201', async () => {
+ const res = await request('POST', '/api/swipes', {
+ profileId: 'p_0_abc',
+ profileName: 'Alex',
+ action: 'like',
+ });
+ assert.equal(res.status, 201);
+ assert.equal(res.body.action, 'like');
+ assert.equal(res.body.profileId, 'p_0_abc');
+ assert.equal(res.body.profileName, 'Alex');
+ assert.ok(res.body.id);
+ assert.ok(res.body.swipedAt);
+ });
+
+ it('records a nope and returns 201', async () => {
+ const res = await request('POST', '/api/swipes', {
+ profileId: 'p_1_def',
+ profileName: 'Jordan',
+ action: 'nope',
+ });
+ assert.equal(res.status, 201);
+ assert.equal(res.body.action, 'nope');
+ });
+
+ it('records a superlike and returns 201', async () => {
+ const res = await request('POST', '/api/swipes', {
+ profileId: 'p_2_ghi',
+ profileName: 'Sam',
+ action: 'superlike',
+ });
+ assert.equal(res.status, 201);
+ assert.equal(res.body.action, 'superlike');
+ });
+
+ it('returns 400 when profileId is missing', async () => {
+ const res = await request('POST', '/api/swipes', {
+ profileName: 'Alex',
+ action: 'like',
+ });
+ assert.equal(res.status, 400);
+ assert.ok(res.body.error);
+ });
+
+ it('returns 400 when profileName is missing', async () => {
+ const res = await request('POST', '/api/swipes', {
+ profileId: 'p_0_abc',
+ action: 'like',
+ });
+ assert.equal(res.status, 400);
+ assert.ok(res.body.error);
+ });
+
+ it('returns 400 for an invalid action', async () => {
+ const res = await request('POST', '/api/swipes', {
+ profileId: 'p_0_abc',
+ profileName: 'Alex',
+ action: 'wink',
+ });
+ assert.equal(res.status, 400);
+ assert.ok(res.body.error);
+ });
+
+ it('returns 400 when profileId is blank whitespace', async () => {
+ const res = await request('POST', '/api/swipes', {
+ profileId: ' ',
+ profileName: 'Alex',
+ action: 'like',
+ });
+ assert.equal(res.status, 400);
+ assert.ok(res.body.error);
+ });
+
+ it('trims whitespace from profileId and profileName', async () => {
+ const res = await request('POST', '/api/swipes', {
+ profileId: ' p_0_abc ',
+ profileName: ' Alex ',
+ action: 'like',
+ });
+ assert.equal(res.status, 201);
+ assert.equal(res.body.profileId, 'p_0_abc');
+ assert.equal(res.body.profileName, 'Alex');
+ });
+});
+
+// ---------------------------------------------------------------------------
+// GET /api/swipes
+// ---------------------------------------------------------------------------
+
+describe('GET /api/swipes', () => {
+ it('returns an empty array when no swipes exist', async () => {
+ const res = await request('GET', '/api/swipes');
+ assert.equal(res.status, 200);
+ assert.deepEqual(res.body.swipes, []);
+ });
+
+ it('returns all recorded swipes in descending order', async () => {
+ await request('POST', '/api/swipes', { profileId: 'p_1', profileName: 'A', action: 'like' });
+ await request('POST', '/api/swipes', { profileId: 'p_2', profileName: 'B', action: 'nope' });
+
+ const res = await request('GET', '/api/swipes');
+ assert.equal(res.status, 200);
+ assert.equal(res.body.swipes.length, 2);
+ // Most recent first
+ assert.equal(res.body.swipes[0].profileId, 'p_2');
+ });
+
+ it('each swipe entry has the expected shape', async () => {
+ await request('POST', '/api/swipes', { profileId: 'p_1', profileName: 'A', action: 'superlike' });
+ const res = await request('GET', '/api/swipes');
+ const swipe = res.body.swipes[0];
+ assert.ok(swipe.id);
+ assert.ok(swipe.profileId);
+ assert.ok(swipe.profileName);
+ assert.ok(swipe.action);
+ assert.ok(swipe.swipedAt);
+ });
+});
+
+// ---------------------------------------------------------------------------
+// GET /api/swipes/stats
+// ---------------------------------------------------------------------------
+
+describe('GET /api/swipes/stats', () => {
+ it('returns zero counts when no swipes exist', async () => {
+ const res = await request('GET', '/api/swipes/stats');
+ assert.equal(res.status, 200);
+ assert.deepEqual(res.body, { like: 0, nope: 0, superlike: 0, total: 0 });
+ });
+
+ it('returns correct counts after mixed swipes', async () => {
+ await request('POST', '/api/swipes', { profileId: 'p_1', profileName: 'A', action: 'like' });
+ await request('POST', '/api/swipes', { profileId: 'p_2', profileName: 'B', action: 'like' });
+ await request('POST', '/api/swipes', { profileId: 'p_3', profileName: 'C', action: 'nope' });
+ await request('POST', '/api/swipes', { profileId: 'p_4', profileName: 'D', action: 'superlike' });
+
+ const res = await request('GET', '/api/swipes/stats');
+ assert.equal(res.status, 200);
+ assert.equal(res.body.like, 2);
+ assert.equal(res.body.nope, 1);
+ assert.equal(res.body.superlike, 1);
+ assert.equal(res.body.total, 4);
+ });
+});
+
+// ---------------------------------------------------------------------------
+// 404
+// ---------------------------------------------------------------------------
+
+describe('Unknown routes', () => {
+ it('returns 404 for an unknown path', async () => {
+ const res = await request('GET', '/api/does-not-exist');
+ assert.equal(res.status, 404);
+ });
+});
diff --git a/backend/vapid.js b/backend/vapid.js
new file mode 100644
index 00000000..5e3d0dab
--- /dev/null
+++ b/backend/vapid.js
@@ -0,0 +1,26 @@
+'use strict';
+
+const webpush = require('web-push');
+const fs = require('fs');
+const path = require('path');
+
+const KEYS_PATH = process.env.VAPID_KEYS_PATH || path.join(__dirname, 'vapid_keys.json');
+
+function loadOrGenerateKeys() {
+ if (fs.existsSync(KEYS_PATH)) {
+ return JSON.parse(fs.readFileSync(KEYS_PATH, 'utf8'));
+ }
+ const keys = webpush.generateVAPIDKeys();
+ fs.writeFileSync(KEYS_PATH, JSON.stringify(keys, null, 2));
+ return keys;
+}
+
+const vapidKeys = loadOrGenerateKeys();
+
+webpush.setVapidDetails(
+ 'mailto:admin@example.com',
+ vapidKeys.publicKey,
+ vapidKeys.privateKey
+);
+
+module.exports = { webpush, vapidKeys };
diff --git a/index.html b/index.html
index 37043a4e..43a5bf24 100644
--- a/index.html
+++ b/index.html
@@ -15,7 +15,7 @@
🔥
Tinder Clone
- frontend only
+ match notifications