17 lines · 578 B · TypeScript
RawDownload
import { createMiddleware, createStart } from "@tanstack/react-start";import { handleApiRequest } from "./api"; const apiRequestMiddleware = createMiddleware({ type: "request" }).server(  ({ pathname, request, next }) => {    if (pathname === "/api" || pathname.startsWith("/api/")) {      const url = new URL(request.url);      url.pathname = url.pathname.replace(/^\/api/, "");      return handleApiRequest(new Request(url, request));    }    return next();  },); export const startInstance = createStart(() => ({  requestMiddleware: [apiRequestMiddleware],}));