Skip to content

Commit

Permalink
Moving CORS redirect logic to affect production environments (#1984)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubwub authored Jan 10, 2025
1 parent c9268c6 commit 1508add
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ import { z } from "zod";
export const maxDuration = 60;
export const revalidate = 0;

// handle CORS preflight requests
export async function OPTIONS(_: NextRequest) {
const response = new NextResponse();
response.headers.set("Access-Control-Allow-Origin", "*");
response.headers.set("Access-Control-Allow-Methods", "POST, OPTIONS");
response.headers.set("Access-Control-Allow-Headers", "Content-Type");
return response;
}

export async function POST(req: NextRequest) {
const bedrock = createAmazonBedrock({
region: "us-west-2",
Expand Down
9 changes: 5 additions & 4 deletions packages/fern-docs/ui/src/search/SearchV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ export function SearchV2(): ReactElement | false {
let chatEndpoint = useApiRoute("/api/fern-docs/search/v2/chat");
let suggestEndpoint = useApiRoute("/api/fern-docs/search/v2/suggest");

// TODO: this is just for testing, this should be removed once it's confirmed that CORS is working
if (process.env.NODE_ENV === "development") {
chatEndpoint = `https://app-staging.buildwithfern.com/api/fern-docs/search/v2/chat`;
suggestEndpoint = `https://app-staging.buildwithfern.com/api/fern-docs/search/v2/suggest`;
// Rerouting to ferndocs.com for production environments to ensure streaming works
// Also see: next.config.mjs, where we set CORS headers
if (process.env.NODE_ENV === "production") {
chatEndpoint = `https://app.ferndocs.com/api/fern-docs/search/v2/chat`;
suggestEndpoint = `https://app.ferndocs.com/api/fern-docs/search/v2/suggest`;
}

const router = useRouter();
Expand Down

0 comments on commit 1508add

Please sign in to comment.