Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move listing redirect to inside component #221

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 !== udMeHostname
sudoryan marked this conversation as resolved.
Show resolved Hide resolved
) {
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
Loading