diff --git a/packages/cms/keystatic/src/keystatic-route-handler.ts b/packages/cms/keystatic/src/keystatic-route-handler.ts index 41ed54602..081b1075e 100644 --- a/packages/cms/keystatic/src/keystatic-route-handler.ts +++ b/packages/cms/keystatic/src/keystatic-route-handler.ts @@ -2,6 +2,28 @@ import { makeRouteHandler } from '@keystatic/next/route-handler'; import config from './keystatic.config'; -export const keystaticRouteHandlers = makeRouteHandler({ +const handlers = makeRouteHandler({ config, }); + +/** + * @name productionGuard + * @description Guard for production environment. Returns 404 if in production. + * @param routeHandler + */ +function productionGuard(routeHandler: (req: Request) => Promise) { + if (process.env.NODE_ENV === 'production') { + return new Response('Not found', { status: 404 }); + } + + return (req: Request) => routeHandler(req); +} + +/** + * @name keystaticRouteHandlers + * @description Route handlers for keystatic + */ +export const keystaticRouteHandlers = { + POST: productionGuard(handlers.POST), + GET: productionGuard(handlers.GET), +}; diff --git a/turbo/generators/templates/keystatic/layout.tsx.hbs b/turbo/generators/templates/keystatic/layout.tsx.hbs index d78a4226a..ef3a5449b 100644 --- a/turbo/generators/templates/keystatic/layout.tsx.hbs +++ b/turbo/generators/templates/keystatic/layout.tsx.hbs @@ -1,7 +1,10 @@ +import { redirect } from 'next/navigation'; import KeystaticAdmin from '@kit/keystatic/admin'; export default function Layout() { - return ( - - ); + if (process.env.NODE_ENV === 'production') { + redirect('/'); + } + + return ; } \ No newline at end of file