import { isEditorOrigin } from "./origin";
import { workbenchResponse } from "./workbench";
import { handlePreview } from "./container-api";
export const WORKBENCH_PATH = "/workbench";
/**
* Requests on the editor origin only ever get the workbench page (static VS Code and extension assets are
* served by the asset layer). Forge pages, APIs and cookies are never available on this origin.
*/
export async function handleEditorOrigin(request: Request, url: URL): Promise<Response | null> {
if (!isEditorOrigin(url)) return null;
if (request.method === "GET" && url.pathname === WORKBENCH_PATH) return workbenchResponse(url);
if (url.pathname.startsWith("/preview/")) return handlePreview(request, url);
return new Response("Not found\n", { status: 404, headers: { "content-type": "text/plain; charset=utf-8" } });
}