From 118df9b82af855bd47517eb205acc0929f04e659 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 14 Oct 2022 20:44:01 +0100 Subject: [PATCH] feat: remove useless file tenant.sever --- src/lib/tenant.server.ts | 52 ---------------------------------------- src/middleware.ts | 10 -------- 2 files changed, 62 deletions(-) delete mode 100644 src/lib/tenant.server.ts diff --git a/src/lib/tenant.server.ts b/src/lib/tenant.server.ts deleted file mode 100644 index 69028ac4..00000000 --- a/src/lib/tenant.server.ts +++ /dev/null @@ -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 -} diff --git a/src/middleware.ts b/src/middleware.ts index 5c2f7fe8..107ea149 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -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