From 9d2f896ae8d2e4e2df99307221c0f19e6b38dd37 Mon Sep 17 00:00:00 2001 From: Fabiano Cruz Date: Wed, 24 Jun 2026 11:23:17 -0300 Subject: [PATCH] feat(x402-demo): public deploy config + PORT from env Dockerfile + railway.json to ship the x402 paywall demo ($0.001 USDC, Base Sepolia) as a public CodeSpar example API; server now reads process.env.PORT for Railway. Co-Authored-By: Claude Opus 4.8 (1M context) --- examples/x402-demo/Dockerfile | 18 ++++++++++++++++++ examples/x402-demo/railway.json | 14 ++++++++++++++ examples/x402-demo/server.ts | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 examples/x402-demo/Dockerfile create mode 100644 examples/x402-demo/railway.json diff --git a/examples/x402-demo/Dockerfile b/examples/x402-demo/Dockerfile new file mode 100644 index 00000000..f4cd477f --- /dev/null +++ b/examples/x402-demo/Dockerfile @@ -0,0 +1,18 @@ +# x402 demo server — public 402 paywall ($0.001 USDC on Base Sepolia). +# Deployed as a CodeSpar example API so agents can pay a real 402 resource. +# Env (set in Railway, NOT baked in): SERVER_ADDRESS (payee 0x), FACILITATOR_URL. +# Do NOT copy .env into the image — it holds the example CLIENT_PRIVATE_KEY. +FROM node:22-slim +WORKDIR /app + +COPY package.json ./ +# Full install (not --omit=dev): the server runs via `tsx`, a devDependency. +RUN npm install --no-audit --no-fund + +COPY server.ts ./ + +# Railway injects PORT; the server reads process.env.PORT (fallback 4021). +ENV PORT=4021 +EXPOSE 4021 + +CMD ["npx", "tsx", "server.ts"] diff --git a/examples/x402-demo/railway.json b/examples/x402-demo/railway.json new file mode 100644 index 00000000..da19d9f5 --- /dev/null +++ b/examples/x402-demo/railway.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://railway.com/railway.schema.json", + "build": { + "builder": "DOCKERFILE", + "dockerfilePath": "Dockerfile", + "watchPatterns": ["examples/x402-demo/**"] + }, + "deploy": { + "healthcheckPath": "/api/health", + "healthcheckTimeout": 10, + "restartPolicyType": "ON_FAILURE", + "restartPolicyMaxRetries": 3 + } +} diff --git a/examples/x402-demo/server.ts b/examples/x402-demo/server.ts index 69731378..95c9eb98 100644 --- a/examples/x402-demo/server.ts +++ b/examples/x402-demo/server.ts @@ -88,7 +88,7 @@ app.get("/api/premium-analysis", (_req, res) => { }); }); -const PORT = 4021; +const PORT = Number(process.env.PORT) || 4021; app.listen(PORT, () => { console.log(`\n x402 Demo Server running on http://localhost:${PORT}`); console.log(` Network: Base Sepolia (eip155:84532)`);