Skip to content

Commit 80a338f

Browse files
authoredMar 4, 2025··
Merge pull request #2199 from navikt/readd-render-from-props
Readd render-from-props method
2 parents 4b66029 + 457a16b commit 80a338f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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;

0 commit comments

Comments
 (0)
Please sign in to comment.