Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ VAPID_SUBJECT=mailto:admin@threatcrush.com
# ─── Self-Hosting ───
# PORT=3000
# NODE_ENV=production

# Crawl gateway (@profullstack/x402-gateway): AI training crawlers pay $1/day over
# x402. A SCOPED CoinPay key (payments:create) and the EVM address that receives
# the USDC. Unset = crawlers still get 402, nothing sold.
COINPAY_X402_KEY=
CRAWL_PAY_TO=
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@profullstack/autoblog": "github:profullstack/autoblog#v0.4.0",
"@profullstack/pluginstore": "^0.1.1",
"@profullstack/stack": "^0.1.3",
"@profullstack/x402-gateway": "^0.1.0",
"@supabase/supabase-js": "^2.101.1",
"@threatcrush/scan": "workspace:*",
"isomorphic-dompurify": "^3.12.0",
Expand Down
43 changes: 0 additions & 43 deletions apps/web/src/app/robots.ts

This file was deleted.

9 changes: 9 additions & 0 deletions apps/web/src/app/robots.txt/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { robotsRoute } from "@profullstack/x402-gateway/next";
import { gateway } from "@/lib/crawl-gateway";

// Generated from the same crawler lists the gateway enforces: training
// crawlers are refused everywhere but /crawl (where they can buy a pass),
// retrieval crawlers are named as welcome, everyone else gets the rules below.
export const GET = robotsRoute(gateway, {
disallow: ["/api/"],
});
27 changes: 27 additions & 0 deletions apps/web/src/lib/crawl-gateway.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createGateway } from "@profullstack/x402-gateway";
import { x402Proxy } from "@profullstack/x402-gateway/next";

/**
* Sells crawl access to AI training crawlers (GPTBot, ClaudeBot, CCBot,
* meta-externalagent, Bytespider, Applebot-Extended, ...) by the day over
* x402, settled by CoinPay in USDC. People, Googlebot and the retrieval
* crawlers behind AI search pass through untouched.
*
* Runs inside the middleware, so nothing here may import Node-only modules.
* The env is read through a non-literal key on purpose: Next inlines
* `process.env.NAME` at build time, and these are runtime secrets. Without
* COINPAY_X402_KEY and CRAWL_PAY_TO the gateway still answers training
* crawlers with 402, just with an empty offer.
*/
const env = (name: string) => process.env[name];

export const gateway = createGateway({
siteUrl: env("SITE_URL") || env("NEXT_PUBLIC_SITE_URL") || "https://threatcrush.com",
siteName: "ThreatCrush",
coinpay: { apiKey: env("COINPAY_X402_KEY") },
payTo: env("CRAWL_PAY_TO"),
contact: "mailto:support@threatcrush.com",
});

/** Resolves to a Response for a refused crawler, or undefined to carry on. */
export const gate = x402Proxy(gateway);
9 changes: 8 additions & 1 deletion apps/web/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { gate } from "@/lib/crawl-gateway";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

Expand Down Expand Up @@ -83,7 +84,13 @@ function rateLimit(req: NextRequest): NextResponse | undefined {
return undefined;
}

export function middleware(req: NextRequest): NextResponse | undefined {
export async function middleware(req: NextRequest): Promise<Response | NextResponse | undefined> {
// Crawl gateway first: AI training crawlers get 402 Payment Required (or the
// sales page at /crawl) unless they present a paid pass. People, Googlebot
// and retrieval crawlers fall through to everything below.
const answer = await gate(req);
if (answer) return answer;

if (req.headers.get("next-action")) {
return new NextResponse(null, { status: 410 });
}
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading