Skip to content

Commit

Permalink
Merge pull request #221 from unstoppabledomains/ryan/move-redirect
Browse files Browse the repository at this point in the history
Move listing redirect to inside component
  • Loading branch information
sudoryan authored Oct 29, 2024
2 parents 442066f + 5424d36 commit 4b1d998
Showing 1 changed file with 13 additions and 46 deletions.
59 changes: 13 additions & 46 deletions server/pages/[domain]/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ const DomainProfile = ({
profileData: initialProfileData,
identity,
}: DomainProfilePageProps) => {
// Redirect to listing page if domain is listed for sale and the host is not ud.me
useEffect(() => {
const udMeHostname = new URL(config.UD_ME_BASE_URL).hostname;
if (
initialProfileData?.isListedForSale &&
typeof window !== 'undefined' && // Make sure we're on client side
window.location.hostname.toLowerCase() !== udMeHostname.toLowerCase()
) {
window.location.replace(`${config.UNSTOPPABLE_WEBSITE_URL}/d/${domain}`);
}
}, [initialProfileData]);

// hooks
const [t] = useTranslationContext();
const {classes, cx} = useStyles();
Expand Down Expand Up @@ -1614,11 +1626,7 @@ const DomainProfile = ({
};

export async function getServerSideProps(props: DomainProfileServerSideProps) {
const {params, req} = props;
const forwardedHost = Array.isArray(req.headers['x-forwarded-host'])
? req.headers['x-forwarded-host'][0]?.trim()
: req.headers['x-forwarded-host']?.split(',')[0]?.trim();
const host = forwardedHost || req.headers.host;
const {params} = props;
const profileServiceUrl = config.PROFILE.HOST_URL;
const domain = params.domain.toLowerCase();
const redirectToSearch = {
Expand All @@ -1633,13 +1641,6 @@ export async function getServerSideProps(props: DomainProfileServerSideProps) {
},
};

const redirectToListingPage = {
redirect: {
destination: `${config.UNSTOPPABLE_WEBSITE_URL}/d/${domain}`,
permanent: false,
},
};

let profileData: SerializedPublicDomainProfileData | undefined;
let identity = null;
try {
Expand All @@ -1665,40 +1666,6 @@ export async function getServerSideProps(props: DomainProfileServerSideProps) {
console.error(`error loading domain profile for ${domain}`, String(e));
}

const udMeHostname = new URL(config.UD_ME_BASE_URL).hostname;
if (domain === 'testingdotcom.com' || domain === '0xtesting.nft') {
console.log(
'Profile page getServerSideProps output:',
JSON.stringify(
{
props: {
resolvedUrl: props.resolvedUrl,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
pathname: (props as any).pathname,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
asPath: (props as any).asPath,
query: props.query,
params: props.params,
},
headers: {
...req.headers,
},
url: req.url,
},
null,
2,
),
);
}
// Redirect to the listing page if domain is listed for sale and the host is not ud.me
if (
typeof host === 'string' &&
host !== udMeHostname &&
profileData?.isListedForSale
) {
return redirectToListingPage;
}

// Redirecting to /search if the domain isn't purchased yet, trying to increase conversion
if (!profileData?.profile?.domainPurchased) {
return redirectToSearch;
Expand Down

0 comments on commit 4b1d998

Please sign in to comment.