core/apps/webapp/app/utils/apiCors.ts
Harshith Mullapudi 4a0a57cb97
Feat: add documents to the kg (#64)
* Feat: add documents to the kg

* Feat: add versioning to documents

* Fix: invalidation of evolved facts

* fix: mcp return

* fix: invalidAt is not displayed in graph popover

* Fix: use document id for the flow

* refactor: consolidate document versioning around sessionId instead of documentId

* fix: add docs link in welcome email

* fix: give more time for larger graphs to settle on

* bump: new version 0.1.20

---------

Co-authored-by: Manoj K <saimanoj58@gmail.com>
2025-09-03 12:39:46 +05:30

36 lines
874 B
TypeScript

import { cors } from "remix-utils/cors";
type CorsMethod = "GET" | "HEAD" | "PUT" | "PATCH" | "POST" | "DELETE";
type CorsOptions = {
methods?: CorsMethod[];
/** Defaults to 5 mins */
maxAge?: number;
origin?: boolean | string;
credentials?: boolean;
exposedHeaders?: string[];
};
export async function apiCors(
request: Request,
response: Response,
options: CorsOptions = { maxAge: 5 * 60 },
): Promise<Response> {
if (hasCorsHeaders(response)) {
return response;
}
return cors(request, response, { ...options });
}
export function makeApiCors(
request: Request,
options: CorsOptions = { maxAge: 5 * 60 },
): (response: Response) => Promise<Response> {
return (response: Response) => apiCors(request, response, options);
}
function hasCorsHeaders(response: Response) {
return response.headers.has("access-control-allow-origin");
}