rallly/packages/backend/next/utils.ts
2023-04-03 10:41:19 +01:00

23 lines
483 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 ("props" in fnRes) {
res.props = {
...res.props,
...fnRes.props,
};
} else {
return fnRes;
}
}
return res;
};
}