import { P } from "ts-pattern";
import { toApiRequest, pipeResponseTo } from "../../../api-handler/node-request-response";
import { pagesRouterRedirectPreviewHandler } from "../handlers/pages-router-redirect-preview";
import { PRERENDER_BYPASS_COOKIE, PREVIEW_DATA_COOKIE } from "../preview";
import { validateApiRoute } from "./base";
const argsPattern = [P.any, P.any];
async function config({
  req,
  res,
  client
}) {
  return {
    req: toApiRequest(req),
    route: validateApiRoute(await apiRequestParams(req)),
    previewCookieNames: [PRERENDER_BYPASS_COOKIE, PREVIEW_DATA_COOKIE],
    sendResponse: (apiResponse) => pipeResponseTo(apiResponse, res),
    revalidationHandler: async (path) => {
      if (path != null) {
        res.revalidate(path);
      } else {
      }
    },
    customRoutes: async (route) => {
      if (route === "/redirect-preview") {
        return { res: await pagesRouterRedirectPreviewHandler(req, res, client) };
      }
      return null;
    }
  };
}
function apiRequestParams(request) {
  return Promise.resolve(request.query);
}
export {
  argsPattern,
  config
};
//# sourceMappingURL=pages-router.js.map