Skip to content
Closed
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
15 changes: 15 additions & 0 deletions apps/docs-proxy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@repo/docs-proxy",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "wrangler dev",
"deploy": "wrangler deploy --minify"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20250620.0",
"typescript": "^5.8.3",
"wrangler": "^4.4.0"
}
}
49 changes: 49 additions & 0 deletions apps/docs-proxy/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const UPSTREAM_BASE = "https://supermemory.mintlify.dev"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new file is not Biome-formatted, and repo CI runs Biome on changed files. The delegated check reported biome ci fails with File content differs from formatting output; please format the file so CI passes.

const CACHE_TTL = 300 // 5 minutes
const FETCH_TIMEOUT_MS = 10000 // 10 seconds

export default {
async fetch(request: Request): Promise<Response> {
const url = new URL(request.url)
const proxyUrl = UPSTREAM_BASE + url.pathname + url.search

const cache = caches.default

if (request.method === "GET") {
const cached = await cache.match(request)
if (cached) return cached
}

const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS)

try {
const proxyRequest = new Request(proxyUrl, request)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new Request(proxyUrl, request) forwards all headers from the first-party request to the Mintlify upstream, including sensitive headers such as Cookie or Authorization. If this worker serves a Supermemory docs URL, domain-scoped cookies or client auth headers could be leaked upstream. Please construct a sanitized upstream header set and explicitly drop sensitive and hop-by-hop headers.

const response = await fetch(proxyRequest, { signal: controller.signal })

if (request.method === "GET" && response.ok) {
const cachedResponse = new Response(response.clone().body, response)
cachedResponse.headers.set(
"Cache-Control",
`public, max-age=${CACHE_TTL}`,
)
await cache.put(request, cachedResponse)
}

return response
} catch (e) {
if (e instanceof Error && e.name === "AbortError") {
return new Response(
"Documentation temporarily unavailable. Please try again in a moment.",
{
status: 504,
headers: { "Content-Type": "text/plain; charset=utf-8" },
},
)
}
throw e
} finally {
clearTimeout(timeoutId)
}
},
}
15 changes: 15 additions & 0 deletions apps/docs-proxy/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"skipLibCheck": true,
"lib": ["ESNext"],
"types": ["@cloudflare/workers-types"],
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
11 changes: 11 additions & 0 deletions apps/docs-proxy/wrangler.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "supermemory-docs-mintlify",
"main": "src/index.ts",
"compatibility_date": "2025-06-20",
"compatibility_flags": [],

"observability": {
"enabled": true
}
}
13 changes: 13 additions & 0 deletions bun.lock

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

Loading