mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-13 22:37:29 +00:00
Migrate logicsrc-web from Vite SPA to Next.js 16 App Router
Replaces the Vite single-page app + custom Node server.js with a Next.js 16.2.6 App Router app. - proxy.ts (src/proxy.ts): www.logicsrc.com -> logicsrc.com 301 over https, preserving path + query (the original request, now via Next 16 Proxy). - One SSR page via an optional catch-all ([[...slug]]) that renders the same marketing/spec page for each known top-level route (/docs, /blog, /openspec, ...) and 404s unknown paths, preserving existing canonical URLs. Markup is a faithful server-rendered port of the old main.ts (SEO upgrade over the prior client render); interactivity (hire-us form, CoinPay button, section scroll) moves to a client component. - API routes ported to app/api/**: hire-us coinpay-checkout + project-request, oauth/coinpay start/callback/session, webhooks/coinpay. Shared logic in src/lib/coinpay.ts (eligibility, payment-rail selection, webhook verify, HMAC session sign/verify, cookies). - commandboard-api (/health + /api/boards|tasks|plugins/*) is no longer mounted in-process; next.config.ts proxies those paths to COMMANDBOARD_API_URL via afterFiles rewrites (our own /api routes match first). - Build/start switch to next build / next start. Contract tests rewritten to exercise proxy.ts, the route handlers, and pure helpers directly (21 passing); Playwright webServer updated. Deployment (Railway): set COMMANDBOARD_API_URL to the commandboard-api service URL and run it as its own service; root start now runs next start. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
cf5d526176
commit
f0a9f3890e
24 changed files with 2102 additions and 1394 deletions
|
|
@ -0,0 +1,95 @@
|
|||
import type { NextRequest } from "next/server";
|
||||
import { json } from "@/lib/http";
|
||||
import { choosePaymentRail, fetchMerchantEligibility, parseJson } from "@/lib/coinpay";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/hire-us/coinpay-checkout — create a $250/week CoinPay checkout for
|
||||
// the Hire Us plan, choosing card/crypto/both based on merchant eligibility.
|
||||
export async function POST(request: NextRequest) {
|
||||
const apiKey = process.env.COINPAY_API_KEY;
|
||||
const eligibilityApiKey = process.env.COINPAY_ELIGIBILITY_API_KEY || process.env.COINPAY_AGENT_API_KEY || apiKey;
|
||||
const businessId = process.env.COINPAY_BUSINESS_ID || process.env.COINPAY_MERCHANT_ID;
|
||||
const eligibilityMerchantId = process.env.COINPAY_ELIGIBILITY_MERCHANT_ID || process.env.COINPAY_MERCHANT_ID;
|
||||
const apiUrl = process.env.COINPAY_API_URL || "https://coinpayportal.com";
|
||||
const blockchain = process.env.COINPAY_HIRE_US_BLOCKCHAIN || "USDC_POL";
|
||||
const publicUrl = process.env.PUBLIC_URL || "https://logicsrc.com";
|
||||
|
||||
if (!apiKey || !businessId) {
|
||||
return json({ success: false, error: "CoinPay checkout is not configured" }, 503);
|
||||
}
|
||||
|
||||
try {
|
||||
const body = (await request.json().catch(() => ({}))) as Record<string, unknown>;
|
||||
const buyerEmail = typeof body.email === "string" ? body.email.trim().slice(0, 160) : "";
|
||||
const eligibility = await fetchMerchantEligibility(apiUrl, eligibilityApiKey, eligibilityMerchantId);
|
||||
const paymentRail = choosePaymentRail(eligibility, blockchain);
|
||||
|
||||
if (!paymentRail) {
|
||||
return json({ success: false, error: "CoinPay checkout is not available for this merchant" }, 503);
|
||||
}
|
||||
|
||||
const checkoutResponse = await fetch(new URL("/api/payments/create", apiUrl), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
authorization: `Bearer ${apiKey}`,
|
||||
"content-type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
business_id: businessId,
|
||||
amount_usd: 250,
|
||||
payment_method: paymentRail.method,
|
||||
currency: paymentRail.currency,
|
||||
...(paymentRail.blockchain ? { blockchain: paymentRail.blockchain } : {}),
|
||||
description: "LogicSRC Hire Us - $250/week",
|
||||
success_url: `${publicUrl}/hire-us?payment=success`,
|
||||
cancel_url: `${publicUrl}/hire-us?payment=cancelled`,
|
||||
redirect_url: `${publicUrl}/hire-us?payment=coinpay`,
|
||||
webhook_url: `${publicUrl}/api/webhooks/coinpay`,
|
||||
metadata: {
|
||||
product: "logicsrc-hire-us",
|
||||
interval: "week",
|
||||
source: "logicsrc.com/hire-us",
|
||||
...(buyerEmail ? { buyer_email: buyerEmail } : {})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const responseText = await checkoutResponse.text();
|
||||
const payload = parseJson(responseText);
|
||||
|
||||
if (!checkoutResponse.ok || payload.success !== true) {
|
||||
console.error("[coinpay] checkout create failed", {
|
||||
status: checkoutResponse.status,
|
||||
error: (payload.error as string) || responseText.slice(0, 300)
|
||||
});
|
||||
return json(
|
||||
{ success: false, error: (payload.error as string) || "CoinPay checkout failed" },
|
||||
checkoutResponse.ok ? 502 : checkoutResponse.status
|
||||
);
|
||||
}
|
||||
|
||||
const payment = (payload.payment as Record<string, unknown>) || {};
|
||||
return json(
|
||||
{
|
||||
success: true,
|
||||
payment: {
|
||||
id: payment.id,
|
||||
amount_usd: Number(payment.amount_usd ?? payment.amount ?? 250),
|
||||
payment_method: payment.stripe_checkout_url ? "card" : paymentRail.method,
|
||||
currency: payment.currency ?? payment.blockchain ?? paymentRail.blockchain ?? paymentRail.currency,
|
||||
crypto_amount: payment.amount_crypto ?? payment.crypto_amount ?? null,
|
||||
address: payment.payment_address ?? null,
|
||||
qr_code: payment.qr_code ?? null,
|
||||
expires_at: payment.expires_at ?? null,
|
||||
status: payment.status ?? "pending",
|
||||
checkout_url: payment.stripe_checkout_url ?? payload.checkout_url ?? payment.checkout_url ?? null
|
||||
}
|
||||
},
|
||||
201
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("[coinpay] checkout request failed", error);
|
||||
return json({ success: false, error: "Unable to reach CoinPay checkout" }, 500);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue