@@ -6,13 +6,14 @@ import React from 'react';
6
6
import { PageAside } from '@/components/PageAside' ;
7
7
import { PageBody , PageCover } from '@/components/PageBody' ;
8
8
import { PageHrefContext , getAbsoluteHref , getPageHref } from '@/lib/links' ;
9
- import { getPagePath , resolveFirstDocument } from '@/lib/pages' ;
9
+ import { checkIsFromMiddleware , getPagePath , resolveFirstDocument } from '@/lib/pages' ;
10
10
import { ContentRefContext } from '@/lib/references' ;
11
11
import { isSpaceIndexable , isPageIndexable } from '@/lib/seo' ;
12
12
import { getContentTitle } from '@/lib/utils' ;
13
13
14
14
import { PageClientLayout } from './PageClientLayout' ;
15
15
import { PagePathParams , fetchPageData , getPathnameParam , normalizePathname } from '../../fetch' ;
16
+ import { headers } from 'next/headers' ;
16
17
17
18
export const runtime = 'edge' ;
18
19
export const dynamic = 'force-dynamic' ;
@@ -24,6 +25,8 @@ export default async function Page(props: {
24
25
params : Promise < PagePathParams > ;
25
26
searchParams : Promise < { fallback ?: string } > ;
26
27
} ) {
28
+ await ensureIsFromMiddleware ( ) ;
29
+
27
30
const { params : rawParams , searchParams : rawSearchParams } = props ;
28
31
29
32
const params = await rawParams ;
@@ -127,6 +130,7 @@ export async function generateViewport({
127
130
} : {
128
131
params : Promise < PagePathParams > ;
129
132
} ) : Promise < Viewport > {
133
+ await ensureIsFromMiddleware ( ) ;
130
134
const { customization } = await fetchPageData ( await params ) ;
131
135
return {
132
136
colorScheme : customization . themes . toggeable
@@ -144,6 +148,8 @@ export async function generateMetadata({
144
148
params : Promise < PagePathParams > ;
145
149
searchParams : Promise < { fallback ?: string } > ;
146
150
} ) : Promise < Metadata > {
151
+ await ensureIsFromMiddleware ( ) ;
152
+
147
153
const { space, pages, page, customization, site, ancestors } = await getPageDataWithFallback ( {
148
154
pagePathParams : await params ,
149
155
searchParams : await searchParams ,
@@ -206,3 +212,15 @@ async function getPageDataWithFallback(args: {
206
212
page,
207
213
} ;
208
214
}
215
+
216
+ /**
217
+ * Returns a page not found if the request is not from the middleware.
218
+ * Some pages can be
219
+ */
220
+ async function ensureIsFromMiddleware ( ) {
221
+ // To check if the request is from the middleware, we check if the x-gitbook-token is set in the headers.
222
+ const fromMiddleware = await checkIsFromMiddleware ( ) ;
223
+ if ( ! fromMiddleware ) {
224
+ notFound ( ) ;
225
+ }
226
+ }
0 commit comments