📦 1. Project Setup (if not done yet)If you already have your Express code in a folder (e.g. writebear-server), you’re good. Otherwise:mkdir writebear-server cd writebear-server npm init -y npm install express axios dotenvCreate the files:index.js (your main server file).env (your Supabase URL, key, and shared secret)vercel.json (to configure Vercel properly)🧾 2. Create index.jsPaste your Express server logic into index.js. For example:const express = require("express"); const axios = require("axios"); require("dotenv").config(); const app = express(); app.use(express.json()); app.post("/verify-receipt", async (req, res) => { const { receipt, device_id } = req.body; if (!receipt || !device_id) return res.status(400).send("Missing fields"); const verifyWithApple = async (url) => { const response = await axios.post(url, { "receipt-data": receipt, "password": process.env.SHARED_SECRET, }); return response.data; }; let result = await verifyWithApple("https://buy.itunes.apple.com/verifyReceipt"); if (result.status === 21007) { result = await verifyWithApple("https://sandbox.itunes.apple.com/verifyReceipt"); } if (result.status !== 0) return res.status(400).json({ error: "Invalid receipt", result }); const latest = result.latest_receipt_info?.slice(-1)[0]; const isActive = latest && parseInt(latest.expires_date_ms) > Date.now(); const originalTransactionId = latest?.original_transaction_id; // ✅ Connect to Supabase and mark is_pro = true const { createClient } = require("@supabase/supabase-js"); const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY); if (isActive) { await supabase.from("devices").upsert({ device_id, is_pro: true, original_transaction_id: originalTransactionId, last_updated: new Date().toISOString(), }); } return res.json({ is_pro: isActive }); }); module.exports = app;🔧 3. Add vercel.json (to route correctly)Create a file called vercel.json:{ "version": 2, "builds": [{ "src": "index.js", "use": "@vercel/node" }], "routes": [ { "src": "/verify-receipt", "dest": "/index.js" } ] }🔑 4. Create .env fileSUPABASE_URL=https://your-project.supabase.co SUPABASE_KEY=your-supabase-service-role-key SHARED_SECRET=your-app-shared-secret
I'll help you create a complete Express.js server for receipt verification with Supabase integration, ready for deployment on Vercel. Let me build this step by step following your requirements.
I've created a complete Express.js server for Apple receipt verification with the following features:
.env
file with your actual Supabase and Apple credentialsnpm run dev
# Install Vercel CLI
npm i -g vercel
# Deploy your project
vercel
# Add your environment variables
vercel env add SUPABASE_URL
vercel env add SUPABASE_KEY
vercel env add SHARED_SECRET
The server follows Express.js best practices and is optimized for Vercel's serverless environment 1. It automatically handles the routing configuration needed for Vercel deployment and includes proper error handling for production use.
To configure the generation, complete these steps:
I detected and automatically synced new changes from main
in PolarServer
.