rallly/packages/backend/next/utils.ts
2023-06-19 19:14:36 +01:00

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;
};
}