Construction mode hides pages from Markdown, MCP and search; MCP rejects non-object messages
createContentHelpers exposes isPathVisible (built from getConstructionMode) and passes it to markdownRoute and mcpPOST; createSearchRoute, createMcpRoute and createMarkdownRoute accept it. A null/number/string JSON-RPC message now gets -32600 instead of crashing the route. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9a72ebfaff
commit
7c05a1dba9
@@ -1,5 +1,6 @@
|
||||
import type { BasePayload } from 'payload'
|
||||
|
||||
import type { PathVisibility } from '../construction/visibility.js'
|
||||
import type { ContentOption } from './types.js'
|
||||
|
||||
import { blocksToMarkdown } from './blocksToMarkdown.js'
|
||||
@@ -187,14 +188,23 @@ function routeOf(
|
||||
* (details only in the server log).
|
||||
*/
|
||||
export function createMarkdownRoute(
|
||||
args: { getCachedPayload: () => Promise<BasePayload> } & CreateMarkdownRendererArgs,
|
||||
args: {
|
||||
getCachedPayload: () => Promise<BasePayload>
|
||||
/** Hide pages the site hides (construction mode) — 404 like an unknown page. */
|
||||
isPathVisible?: PathVisibility
|
||||
} & CreateMarkdownRendererArgs,
|
||||
): { GET: (req: Request, ctx: MarkdownRouteContext) => Promise<Response> } {
|
||||
const { getCachedPayload, ...rendererArgs } = args
|
||||
const { getCachedPayload, isPathVisible, ...rendererArgs } = args
|
||||
const render = createMarkdownRenderer(rendererArgs)
|
||||
return {
|
||||
GET: async (_req, { params }) => {
|
||||
try {
|
||||
const { slug, locale } = routeOf(await params, rendererArgs.config)
|
||||
if (isPathVisible) {
|
||||
const multilingual = (rendererArgs.config?.locales.length ?? 0) > 1
|
||||
const path = `/${[...(multilingual ? [locale] : []), ...(slug ?? [])].join('/')}`
|
||||
if (!(await isPathVisible(path, locale))) {return markdownResponse(null, {})}
|
||||
}
|
||||
const md = await render({ slug, locale, payload: await getCachedPayload() })
|
||||
return markdownResponse(md, { canonical: canonicalOf(rendererArgs.baseUrl, rendererArgs.config, locale, slug) })
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user