( context: GetServerSidePropsContext, isSubdomainbasedRouting: boolean )
| 11 | import { allowAccess, ssr } from 'services/ssr/common'; |
| 12 | |
| 13 | export async function threadGetServerSideProps( |
| 14 | context: GetServerSidePropsContext, |
| 15 | isSubdomainbasedRouting: boolean |
| 16 | ) { |
| 17 | try { |
| 18 | const isCrawler = isBot(context?.req?.headers?.['user-agent'] || ''); |
| 19 | |
| 20 | const { props, notFound, ...rest } = await ssr( |
| 21 | context, |
| 22 | allowAccess, |
| 23 | isCrawler |
| 24 | ); |
| 25 | |
| 26 | if (rest.redirect) { |
| 27 | return RedirectTo(rest.location); |
| 28 | } |
| 29 | |
| 30 | if (notFound || !props) { |
| 31 | return NotFound(); |
| 32 | } |
| 33 | |
| 34 | const { channels, currentCommunity, dms, settings, publicChannels } = props; |
| 35 | |
| 36 | const threadId = context.params?.threadId as string; |
| 37 | const communityName = context.params?.communityName as string; |
| 38 | const slug = context.params?.slug as string | undefined; |
| 39 | |
| 40 | const id = parseInt(threadId); |
| 41 | if (!id) { |
| 42 | throw new Error('Thread not found'); |
| 43 | } |
| 44 | |
| 45 | const thread = await findThreadByIncrementId(id); |
| 46 | |
| 47 | if (!thread || !thread?.channel?.accountId) { |
| 48 | throw new Error('Thread not found'); |
| 49 | } |
| 50 | |
| 51 | if (thread?.channel?.accountId !== currentCommunity.id) { |
| 52 | throw new Error('Thread not found'); |
| 53 | } |
| 54 | |
| 55 | if ( |
| 56 | shouldRedirectToDomain({ |
| 57 | account: currentCommunity, |
| 58 | communityName, |
| 59 | isSubdomainbasedRouting, |
| 60 | }) |
| 61 | ) { |
| 62 | return redirectThreadToDomain({ |
| 63 | account: currentCommunity, |
| 64 | communityName, |
| 65 | settings, |
| 66 | threadId, |
| 67 | slug, |
| 68 | }); |
| 69 | } |
| 70 |
no test coverage detected