mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-29 18:26:34 +02:00
29 lines
574 B
TypeScript
29 lines
574 B
TypeScript
import { GetServerSideProps } from "next";
|
|
|
|
export function composeGetServerSideProps(
|
|
...fns: GetServerSideProps[]
|
|
): GetServerSideProps {
|
|
return async (ctx) => {
|
|
const res = { props: {} };
|
|
for (const getServerSideProps of fns) {
|
|
const fnRes = await getServerSideProps(ctx);
|
|
|
|
if ("notFound" in fnRes) {
|
|
return fnRes;
|
|
}
|
|
|
|
if ("redirect" in fnRes) {
|
|
return fnRes;
|
|
}
|
|
|
|
if ("props" in fnRes) {
|
|
res.props = {
|
|
...res.props,
|
|
...fnRes.props,
|
|
};
|
|
}
|
|
}
|
|
|
|
return res;
|
|
};
|
|
}
|