feat: remove useless file tenant.sever
This commit is contained in:
parent
205013496e
commit
118df9b82a
|
|
@ -1,52 +0,0 @@
|
|||
import { OUR_DOMAIN } from "./env"
|
||||
import { toGateway } from "~/lib/ipfs-parser"
|
||||
|
||||
export const getTenant = async (request: Request, search: URLSearchParams) => {
|
||||
const host = request.headers.get("host")
|
||||
|
||||
if (!OUR_DOMAIN) {
|
||||
throw new Error("missing OUR_DOMAIN env")
|
||||
}
|
||||
|
||||
const OUR_DOMAIN_SUFFIX = `.${OUR_DOMAIN}`
|
||||
if (host && host !== OUR_DOMAIN) {
|
||||
if (host.endsWith(OUR_DOMAIN_SUFFIX)) {
|
||||
const subdomain = host.replace(OUR_DOMAIN_SUFFIX, "")
|
||||
const res = await fetch(
|
||||
`https://indexer.crossbell.io/v1/handles/${subdomain}/character`,
|
||||
)
|
||||
const char = await res.json()
|
||||
const customDomain =
|
||||
char?.metadata?.content?.attributes?.find(
|
||||
(a: any) => a.trait_type === "xlog_custom_domain",
|
||||
)?.value || ""
|
||||
if (customDomain) {
|
||||
return {
|
||||
redirect: /^https?:\/\//.test(customDomain)
|
||||
? customDomain
|
||||
: `https://${customDomain}`,
|
||||
subdomain: subdomain,
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
subdomain: subdomain,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const res = await fetch(
|
||||
`https://cloudflare-dns.com/dns-query?name=_xlog-challenge.${host}&type=TXT`,
|
||||
{
|
||||
headers: {
|
||||
accept: "application/dns-json",
|
||||
},
|
||||
},
|
||||
)
|
||||
const txt = await res.json()
|
||||
const tenant = txt?.Answer?.[0]?.data.replace(/^"|"$/g, "")
|
||||
return {
|
||||
subdomain: tenant,
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -1,16 +1,6 @@
|
|||
import { NextRequest, NextResponse } from "next/server"
|
||||
import { IS_PROD } from "~/lib/constants"
|
||||
import { DISCORD_LINK } from "~/lib/env"
|
||||
import { FLY_REGION, IS_PRIMARY_REGION, PRIMARY_REGION } from "~/lib/env.server"
|
||||
import { getTenant } from "~/lib/tenant.server"
|
||||
|
||||
const METHODS_TO_NOT_REPLAY = ["GET", "HEAD", "OPTIONS"]
|
||||
|
||||
const ALWAYS_REPLAY_ROUTES = [
|
||||
"/api/login",
|
||||
"/api/login-complete",
|
||||
"/api/logout",
|
||||
]
|
||||
|
||||
export default async function middleware(req: NextRequest) {
|
||||
const { pathname } = req.nextUrl
|
||||
|
|
|
|||
Loading…
Reference in New Issue