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