Skip to content
Merged
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
31 changes: 27 additions & 4 deletions worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,27 @@ export default {
// Check if the path already has a version prefix (/v1/ or /v2/)
const hasVersionPrefix = /^\/v[12]\//.test(normalizedPath);

// Case 1: Root path → redirect to /v2/
// Case 1: Root path → redirect to /v2
if (normalizedPath === "/" || normalizedPath === "") {
url.pathname = "/v2/";
url.pathname = "/v2";
return Response.redirect(url.toString(), 301);
}

// Case 2: Already versioned (/v1/* or /v2/*) → proxy through
if (hasVersionPrefix) {
return fetch(request);
// Create a new request with the Mintlify backend URL
// This proxies to the actual Mintlify-hosted documentation
const backendUrl = new URL(request.url);
backendUrl.hostname = 'flipt.mintlify.app';

const backendRequest = new Request(backendUrl.toString(), {
method: request.method,
headers: request.headers,
body: request.body,
redirect: 'manual'
});

return fetch(backendRequest);
}

// Case 3: Excluded paths (static assets, APIs, etc.)
Expand Down Expand Up @@ -50,7 +62,18 @@ export default {
});

if (shouldExclude) {
return fetch(request);
// Proxy static assets to the Mintlify backend
const backendUrl = new URL(request.url);
backendUrl.hostname = 'flipt.mintlify.app';

const backendRequest = new Request(backendUrl.toString(), {
method: request.method,
headers: request.headers,
body: request.body,
redirect: 'manual'
});

return fetch(backendRequest);
}

// Case 4: Unversioned path → redirect to /v1/*
Expand Down
Loading