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],}));
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],
}));