File tree 1 file changed +32
-0
lines changed
packages/nextjs/src/pages
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { GetServerSideProps } from 'next' ;
2
+ import { parseBody } from 'next/dist/server/api-utils/node/parse-body' ;
3
+ import { validateSecretHeader } from '@/shared/auth' ;
4
+ import { PageBase } from 'components/PageBase' ;
5
+
6
+ // Render a page using props from the request body
7
+ export const getServerSideProps : GetServerSideProps = async ( { req, res } ) => {
8
+ if ( ! validateSecretHeader ( req ) ) {
9
+ return {
10
+ notFound : true ,
11
+ } ;
12
+ }
13
+
14
+ if ( req . method !== 'POST' ) {
15
+ return ( res as any ) . status ( 405 ) . send ( ) ;
16
+ }
17
+
18
+ const contentProps = ( await parseBody ( req , '5MB' ) ) ?. contentProps ;
19
+
20
+ if ( ! contentProps ) {
21
+ // The type for req/res is incomplete...
22
+ return ( res as any ) . status ( 400 ) . send ( 'Missing contentProps in request body' ) ;
23
+ }
24
+
25
+ return {
26
+ props : {
27
+ content : contentProps ,
28
+ } ,
29
+ } ;
30
+ } ;
31
+
32
+ export default PageBase ;
You can’t perform that action at this time.
0 commit comments