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
3 changes: 3 additions & 0 deletions bun.lock

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"dependencies": {
"@libsql/client": "^0.15.0",
"@profullstack/x402-gateway": "^0.1.0",
"commander": "^12.1.0",
"smol-toml": "^1.3.1",
"zod": "^3.23.8"
Expand Down
24 changes: 24 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* GET /* -> static assets / SPA shell
*/
import { join, normalize } from "node:path";
import { createGateway } from "@profullstack/x402-gateway";
import { loadConfig } from "./config.ts";
import { getDb, migrate } from "./db/index.ts";
import { buildRegistry, getAiProvider } from "./registry.ts";
Expand Down Expand Up @@ -407,13 +408,36 @@ async function candidateTickers(topic: string | null, limit: number): Promise<st
}
}

/**
* Training crawlers (GPTBot, ClaudeBot, CCBot, meta-externalagent, Bytespider,
* Applebot-Extended) pay by the day over x402 (@profullstack/x402-gateway).
* People, search engines and retrieval crawlers pass through untouched.
*/
const crawlGateway = createGateway({
siteUrl: process.env.SITE_URL ?? "https://advis0r.com",
siteName: "advis0r",
coinpay: { apiKey: process.env.COINPAY_X402_KEY },
payTo: process.env.CRAWL_PAY_TO,
contact: "mailto:anthony@profullstack.com",
});

const server = Bun.serve({
port,
idleTimeout: 60,
async fetch(req) {
const url = new URL(req.url);
const p = url.pathname;

// Crawl gateway first: a refused training crawler gets 402 (or the sales
// page at /crawl) before anything below runs.
const refused = await crawlGateway.handle(req);
if (refused) return refused;
if (p === "/robots.txt") {
return new Response(crawlGateway.robotsTxt({ disallow: ["/api/"] }), {
headers: { "content-type": "text/plain; charset=utf-8" },
});
}

// Canonicalize: strip a leading "www." from the host on every request.
const host = req.headers.get("host") ?? "";
if (host.toLowerCase().startsWith("www.")) {
Expand Down
Loading