feat: validate custom domains on the front end to reduce response time
This commit is contained in:
parent
644aa0ec4f
commit
74121264df
|
|
@ -8,6 +8,8 @@ import { BlockchainInfo } from "~/components/common/BlockchainInfo"
|
|||
import { useGetSiteSubscriptions } from "~/queries/site"
|
||||
import { useGetSite } from "~/queries/site"
|
||||
import { useGetPage } from "~/queries/page"
|
||||
import { OUR_DOMAIN, SITE_URL } from "~/lib/env"
|
||||
import { IS_PROD } from "~/lib/constants"
|
||||
|
||||
export type SiteLayoutProps = {
|
||||
children: React.ReactNode
|
||||
|
|
@ -32,6 +34,18 @@ export const SiteLayout: React.FC<SiteLayoutProps> = ({ children, title }) => {
|
|||
siteId: domainOrSubdomain,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (site.data) {
|
||||
if (
|
||||
window.location.host.split(".").slice(-2).join(".") !== OUR_DOMAIN &&
|
||||
window.location.host !== site.data?.custom_domain &&
|
||||
IS_PROD
|
||||
) {
|
||||
window.location.href = SITE_URL
|
||||
}
|
||||
}
|
||||
}, [site.isSuccess, site.data])
|
||||
|
||||
return (
|
||||
<>
|
||||
<SEOHead
|
||||
|
|
|
|||
|
|
@ -43,37 +43,8 @@ export const getTenant = async (request: Request, search: URLSearchParams) => {
|
|||
)
|
||||
const txt = await res.json()
|
||||
const tenant = txt?.Answer?.[0]?.data.replace(/^"|"$/g, "")
|
||||
if (tenant) {
|
||||
const res = await fetch(
|
||||
`https://indexer.crossbell.io/v1/handles/${tenant}/character`,
|
||||
)
|
||||
const char = await res.json()
|
||||
if (!char?.metadata?.content && char?.metadata?.uri) {
|
||||
char.metadata.content = await (
|
||||
await fetch(
|
||||
toGateway(char?.metadata?.uri, {
|
||||
needRequestAtServerSide: true,
|
||||
}),
|
||||
{
|
||||
...(typeof window === "undefined" && {
|
||||
headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
|
||||
},
|
||||
}),
|
||||
},
|
||||
)
|
||||
).json()
|
||||
}
|
||||
const customDomain =
|
||||
char?.metadata?.content?.attributes?.find(
|
||||
(a: any) => a.trait_type === "xlog_custom_domain",
|
||||
)?.value || ""
|
||||
if (customDomain && customDomain === host) {
|
||||
return {
|
||||
subdomain: tenant,
|
||||
}
|
||||
}
|
||||
return {
|
||||
subdomain: tenant,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue