Added SSR

This commit is contained in:
Sebastian Seedorf
2022-08-17 11:52:56 +02:00
parent fe7e6d8ae2
commit 9660f0cf34
16 changed files with 1869 additions and 1834 deletions

38
src/getServerSideProps.ts Normal file
View File

@@ -0,0 +1,38 @@
import {GetServerSideProps} from "next";
import {getGroup, setGroups} from "./database/groups";
import {Dict, Group} from "./types";
export interface PropsGroupProvider {
id: string
groups: Dict<Group>
ignored: string[]
base: string[]
}
export const getServerSidePropsGroupProvider: GetServerSideProps<PropsGroupProvider> = async ({query}) => {
const id = Array.isArray(query?.id) ? query.id[0] : query?.id
const data = id && await getGroup(id)
if (data) {
return {
props: {
id: data._id.toString(),
groups: data.groups,
ignored: data.ignored,
base: data.base
}
}
} else if (!id) {
const newId = await setGroups({groups: {}, base: [], ignored: []})
return {
redirect: {
destination: `?id=${newId}`,
permanent: false,
}
}
} else {
console.log(data)
return {
notFound: true
}
}
}