( context: GetServerSidePropsContext, isSubdomainbasedRouting: boolean )
| 16 | import { buildCursor } from 'utilities/buildCursor'; |
| 17 | |
| 18 | export async function topicGetServerSideProps( |
| 19 | context: GetServerSidePropsContext, |
| 20 | isSubdomainbasedRouting: boolean |
| 21 | ) { |
| 22 | const isCrawler = isBot(context?.req?.headers?.['user-agent'] || ''); |
| 23 | |
| 24 | const { props, notFound, ...rest } = await ssr( |
| 25 | context, |
| 26 | allowAccess, |
| 27 | isCrawler |
| 28 | ); |
| 29 | |
| 30 | if (rest.redirect) { |
| 31 | return RedirectTo(rest.location); |
| 32 | } |
| 33 | |
| 34 | if (notFound || !props) { |
| 35 | return NotFound(); |
| 36 | } |
| 37 | |
| 38 | const { channels, currentCommunity, settings, dms, publicChannels } = props; |
| 39 | |
| 40 | const communityName = context.params?.communityName as string; |
| 41 | const channelName = context.params?.channelName as string; |
| 42 | const page = context.params?.page as string | undefined; |
| 43 | |
| 44 | const channel = findChannelOrGetLandingChannel( |
| 45 | [...channels, ...dms, ...publicChannels], |
| 46 | channelName |
| 47 | ); |
| 48 | if (!channel) return NotFound(); |
| 49 | |
| 50 | if ( |
| 51 | shouldRedirectToDomain({ |
| 52 | account: currentCommunity, |
| 53 | communityName, |
| 54 | isSubdomainbasedRouting, |
| 55 | }) |
| 56 | ) { |
| 57 | return redirectChannelToDomain({ |
| 58 | account: currentCommunity, |
| 59 | communityName, |
| 60 | settings, |
| 61 | channelName, |
| 62 | channel, |
| 63 | }); |
| 64 | } |
| 65 | |
| 66 | if (isCrawler) { |
| 67 | if (!channelName) { |
| 68 | // should be redirect to default_channel |
| 69 | return resolveCrawlerRedirect({ |
| 70 | isSubdomainbasedRouting, |
| 71 | communityName, |
| 72 | settings, |
| 73 | channel, |
| 74 | }); |
| 75 | } |
no test coverage detected