MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / threadGetServerSideProps

Function threadGetServerSideProps

apps/web/services/ssr/threads.ts:13–88  ·  view source on GitHub ↗
(
  context: GetServerSidePropsContext,
  isSubdomainbasedRouting: boolean
)

Source from the content-addressed store, hash-verified

11import { allowAccess, ssr } from 'services/ssr/common';
12
13export 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

Callers 5

getServerSidePropsFunction · 0.90
getServerSidePropsFunction · 0.90
getServerSidePropsFunction · 0.90
getServerSidePropsFunction · 0.90
threads.test.tsFile · 0.90

Calls 10

ssrFunction · 0.90
RedirectToFunction · 0.90
NotFoundFunction · 0.90
findThreadByIncrementIdFunction · 0.90
shouldRedirectToDomainFunction · 0.90
redirectThreadToDomainFunction · 0.90
serializeThreadFunction · 0.90
errorMethod · 0.65
isBotFunction · 0.50
findMethod · 0.45

Tested by

no test coverage detected