From 8b1aef4ecb0b95f981e3137bdf0b2590662a9485 Mon Sep 17 00:00:00 2001 From: reaper Date: Wed, 13 Sep 2023 07:10:34 +0530 Subject: [PATCH] Update astro-disable-admin-ui-in-production.mdoc (#635) --- .../astro-disable-admin-ui-in-production.mdoc | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/docs/src/content/pages/recipes/astro-disable-admin-ui-in-production.mdoc b/docs/src/content/pages/recipes/astro-disable-admin-ui-in-production.mdoc index 728ee6612..ac2627281 100644 --- a/docs/src/content/pages/recipes/astro-disable-admin-ui-in-production.mdoc +++ b/docs/src/content/pages/recipes/astro-disable-admin-ui-in-production.mdoc @@ -35,20 +35,29 @@ export const prerender = false You will need to do the same for the `api/keystatic` routes: -```jsx +```diff // src/pages/api/keystatic/[...params].ts import { makeHandler } from '@keystatic/astro/api' import keystaticConfig from '../../../../keystatic.config' ++ import { APIContext } from 'astro' + +- export const all = makeHandler({ +- config: keystaticConfig, +- }) + ++ export const all = ({ ...params }: APIContext) => { ++ if (import.meta.env.MODE === 'production') { ++ return params.redirect('/', 307) ++ } + ++ return makeHandler({ ++ config: keystaticConfig, ++ })(params) ++} -export const all = makeHandler({ - config: keystaticConfig, -}) export const prerender = false -+ if (import.meta.env.MODE === 'production') { -+ return Astro.redirect('/') -+ } ``` ## Excluding routes from sitemap