import handler from "@tanstack/react-start/server-entry";
import { handleGitRequest, matchGitRoute } from "./server/git/proxy";
import { handleJobApi, handleRunnerApi, reapStaleRunnerJobs } from "./server/ci/runner-api";
import { handleQueueBatch } from "./server/events/consumer";
import type { QueueMessage } from "./server/events/emit";
import { HttpError } from "./server/errors";
import { finishGithubLogin, startGithubLogin } from "./server/github-oauth";
import { handleRawRoutes } from "./server/raw";
import { handleLfsRequest, matchLfsRoute } from "./server/lfs/api";
import { handlePagesRequest } from "./server/pages/serve";
import { handleSecurityApi } from "./server/security/api";
import { handleSecurityBatch, SECURITY_QUEUE } from "./server/security/queue";
export { Runner } from "./server/ci/runner-do";
export { CiRunWorkflow } from "./server/ci/run-workflow";
export { PushWorkflow } from "./server/events/push-workflow";
export { PagesDeployWorkflow } from "./server/pages/workflow";
const RUNNER_API_PREFIX = "/api/runner/";
const JOB_API_PREFIX = "/api/";
async function route(request: Request, ctx: ExecutionContext): Promise<Response | null> {
const pages = await handlePagesRequest(request);
if (pages) return pages;
const url = new URL(request.url);
const gitRoute = matchGitRoute(url);
if (gitRoute) return handleGitRequest(request, gitRoute, ctx);
const lfsRoute = matchLfsRoute(url);
if (lfsRoute) return handleLfsRequest(request, lfsRoute);
if (url.pathname.startsWith(RUNNER_API_PREFIX)) {
return handleRunnerApi(request, url.pathname.slice(RUNNER_API_PREFIX.length));
}
if (url.pathname.startsWith("/api/jobs/") || url.pathname.startsWith("/api/artifacts/")) {
return handleJobApi(request, url.pathname.slice(JOB_API_PREFIX.length));
}
const securityApi = await handleSecurityApi(request, url);
if (securityApi) return securityApi;
if (url.pathname === "/auth/github") return startGithubLogin(request);
if (url.pathname === "/auth/github/callback") return finishGithubLogin(request);
return handleRawRoutes(request, url);