({
hostname,
pathname,
url,
userAgent,
}: {
hostname: string | null;
pathname: string;
url: NextURL;
userAgent: string | null;
})
| 40 | hostname.indexOf('linen.dev') > -1 ? 'www.linen.dev' : hostname; |
| 41 | |
| 42 | export function rewrite({ |
| 43 | hostname, |
| 44 | pathname, |
| 45 | url, |
| 46 | userAgent, |
| 47 | }: { |
| 48 | hostname: string | null; |
| 49 | pathname: string; |
| 50 | url: NextURL; |
| 51 | userAgent: string | null; |
| 52 | }) { |
| 53 | function isLocalIpAddress(hostname: string | null) { |
| 54 | if (!hostname) { |
| 55 | return false; |
| 56 | } |
| 57 | return hostname.startsWith('192.168.1.'); |
| 58 | } |
| 59 | if (isLocalIpAddress(hostname)) { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | if (pathname === '/sitemap.xml') { |
| 64 | return { |
| 65 | rewrite: `${LINEN_STATIC_CDN}/sitemap/${cleanLinenHost( |
| 66 | hostname || 'linen.dev' |
| 67 | )}/sitemap.xml`, |
| 68 | }; |
| 69 | } |
| 70 | if (pathname === '/robots.txt') { |
| 71 | return { |
| 72 | rewrite: `${LINEN_STATIC_CDN}/sitemap/${cleanLinenHost( |
| 73 | hostname || 'linen.dev' |
| 74 | )}/robots.txt`, |
| 75 | }; |
| 76 | } |
| 77 | |
| 78 | if (pathname.startsWith('/s/') && isBot(userAgent || '')) { |
| 79 | url.pathname = url.pathname.replace('/s/', '/ssr/'); |
| 80 | return { rewrite: url.toString() }; |
| 81 | } |
| 82 | |
| 83 | if (!isSubdomainbasedRouting(hostname || '')) { |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | //Community name is the subdomain of the request or the full url if it's a redirect |
| 88 | const communityName = getCommunityName(IS_PRODUCTION, hostname); |
| 89 | |
| 90 | if (!isTopLevelPathname(pathname) && communityName !== '') { |
| 91 | url.pathname = `/s/${communityName}${pathname}`; |
| 92 | url.searchParams.append('customDomain', '1'); |
| 93 | |
| 94 | if (isBot(userAgent || '')) { |
| 95 | url.pathname = url.pathname.replace('/s/', '/ssr/'); |
| 96 | return { rewrite: url.toString() }; |
| 97 | } |
| 98 | |
| 99 | return { rewrite: url.toString() }; |
no test coverage detected