From 41a35b54608a8bb67b59e7409989774bda8b3577 Mon Sep 17 00:00:00 2001 From: Danijel Martinek Date: Mon, 6 Apr 2026 15:57:04 +0200 Subject: [PATCH] fix(cms): add Payload REST API + GraphQL route handlers, revert to inline serverFunction --- .../src/app/(payload)/api/[...slug]/route.ts | 19 +++++++++++++++++++ .../src/app/(payload)/api/graphql/route.ts | 6 ++++++ apps/cms/src/app/(payload)/layout.tsx | 13 +++++++++++-- apps/cms/src/app/(payload)/serverFunction.ts | 14 -------------- 4 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 apps/cms/src/app/(payload)/api/[...slug]/route.ts create mode 100644 apps/cms/src/app/(payload)/api/graphql/route.ts delete mode 100644 apps/cms/src/app/(payload)/serverFunction.ts diff --git a/apps/cms/src/app/(payload)/api/[...slug]/route.ts b/apps/cms/src/app/(payload)/api/[...slug]/route.ts new file mode 100644 index 0000000..dc8ba37 --- /dev/null +++ b/apps/cms/src/app/(payload)/api/[...slug]/route.ts @@ -0,0 +1,19 @@ +/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ +/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ +import config from "@payload-config"; +import "@payloadcms/next/css"; +import { + REST_DELETE, + REST_GET, + REST_OPTIONS, + REST_PATCH, + REST_POST, + REST_PUT, +} from "@payloadcms/next/routes"; + +export const GET = REST_GET(config); +export const POST = REST_POST(config); +export const DELETE = REST_DELETE(config); +export const PATCH = REST_PATCH(config); +export const PUT = REST_PUT(config); +export const OPTIONS = REST_OPTIONS(config); diff --git a/apps/cms/src/app/(payload)/api/graphql/route.ts b/apps/cms/src/app/(payload)/api/graphql/route.ts new file mode 100644 index 0000000..d138a67 --- /dev/null +++ b/apps/cms/src/app/(payload)/api/graphql/route.ts @@ -0,0 +1,6 @@ +/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ +/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ +import config from "@payload-config"; +import { GRAPHQL_POST } from "@payloadcms/next/routes"; + +export const POST = GRAPHQL_POST(config); diff --git a/apps/cms/src/app/(payload)/layout.tsx b/apps/cms/src/app/(payload)/layout.tsx index 0eb1931..c78ffef 100644 --- a/apps/cms/src/app/(payload)/layout.tsx +++ b/apps/cms/src/app/(payload)/layout.tsx @@ -2,17 +2,26 @@ /* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ import config from "@payload-config"; import "@payloadcms/next/css"; -import { RootLayout } from "@payloadcms/next/layouts"; +import type { ServerFunctionClient } from "payload"; +import { handleServerFunctions, RootLayout } from "@payloadcms/next/layouts"; import React from "react"; import { importMap } from "./admin/importMap.js"; -import { serverFunction } from "./serverFunction"; import "./custom.scss"; type Args = { children: React.ReactNode; }; +const serverFunction: ServerFunctionClient = async function (args) { + "use server"; + return handleServerFunctions({ + ...args, + config, + importMap, + }); +}; + const Layout = ({ children }: Args) => ( { - return handleServerFunctions({ - ...args, - config, - importMap, - }); -};