* remove ssrInit completely * remove instances of dehydratedState * fix * refactor * fix type checks * fix linting * Refactor * Refactor * remove log
22 lines
606 B
TypeScript
22 lines
606 B
TypeScript
import type { GetServerSideProps, GetServerSidePropsContext } from "next";
|
|
import { notFound, redirect } from "next/navigation";
|
|
|
|
export const withAppDirSsr =
|
|
<T extends Record<string, any>>(getServerSideProps: GetServerSideProps<T>) =>
|
|
async (context: GetServerSidePropsContext) => {
|
|
const ssrResponse = await getServerSideProps(context);
|
|
|
|
if ("redirect" in ssrResponse) {
|
|
redirect(ssrResponse.redirect.destination);
|
|
}
|
|
if ("notFound" in ssrResponse) {
|
|
notFound();
|
|
}
|
|
|
|
const props = await Promise.resolve(ssrResponse.props);
|
|
|
|
return {
|
|
...props,
|
|
};
|
|
};
|