Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

supported countries api route

Pedro Ladeirafd87680983e9
diff --git a/apps/web/app/(ee)/app.dub.co/embed/supported-countries/page.tsx b/apps/web/app/(ee)/app.dub.co/embed/supported-countries/page.tsx
deleted file mode 100644
index 27d1f794a8..0000000000
--- a/apps/web/app/(ee)/app.dub.co/embed/supported-countries/page.tsx
+++ /dev/null
@@ -1,75 +0,0 @@
-"use client";
-
-import { useMediaQuery } from "@dub/ui";
-import {
- cn,
- CONNECT_SUPPORTED_COUNTRIES,
- COUNTRIES,
- PAYPAL_SUPPORTED_COUNTRIES,
-} from "@dub/utils";
-import { useState } from "react";
-
-export default function SupportedCountriesEmbed() {
- const supportedCountries = [
- ...CONNECT_SUPPORTED_COUNTRIES,
- ...PAYPAL_SUPPORTED_COUNTRIES,
- ];
- const sortedCountries = supportedCountries.sort((a, b) =>
- COUNTRIES[a].localeCompare(COUNTRIES[b]),
- );
- return <CountryGrid countries={sortedCountries} />;
-}
-
-function CountryGrid({ countries }: { countries: string[] }) {
- const { isMobile } = useMediaQuery();
- const showCount = isMobile ? 16 : 30;
- const [expanded, setExpanded] = useState(false);
-
- const displayCountries =
- countries.length <= showCount || expanded
- ? countries
- : countries.slice(0, showCount);
-
- return (
- <div className="not-prose relative px-2">
- <div
- className={cn(
- "grid grid-cols-2 gap-5 py-4 sm:grid-cols-3",
- countries.length > showCount && !expanded && "max-h-[420px]",
- countries.length > showCount && expanded && "pb-12",
- )}
- >
- {displayCountries.map((country) => (
- <div key={country} className="flex items-center gap-3">
- <img
- src={`https://hatscripts.github.io/circle-flags/flags/${country.toLowerCase()}.svg`}
- alt={country}
- width={32}
- height={32}
- className="size-5 rounded-full border border-neutral-200 shadow-md"
- draggable={false}
- />
- <span className="text-sm font-medium">{COUNTRIES[country]}</span>
- </div>
- ))}
- </div>
- {countries.length > showCount && (
- <>
- {!expanded && (
- <div className="absolute bottom-0 h-24 w-full bg-gradient-to-t from-neutral-50 to-transparent" />
- )}
- <button
- onClick={() => setExpanded(!expanded)}
- className={`absolute left-1/2 -translate-x-1/2 transform rounded-full border border-gray-200 bg-white px-4 py-1 text-sm text-gray-500 shadow-sm hover:text-gray-700 ${
- expanded ? "-bottom-2" : "bottom-6"
- }`}
- >
- {expanded
- ? "Show less"
- : `Show ${countries.length - showCount} more`}
- </button>
- </>
- )}
- </div>
- );
-}
diff --git a/apps/web/app/api/supported-countries/route.ts b/apps/web/app/api/supported-countries/route.ts
new file mode 100644
index 0000000000..c237607377
--- /dev/null
+++ b/apps/web/app/api/supported-countries/route.ts
@@ -0,0 +1,24 @@
+import {
+ CONNECT_SUPPORTED_COUNTRIES,
+ COUNTRIES,
+ PAYPAL_SUPPORTED_COUNTRIES,
+} from "@dub/utils";
+import { NextResponse } from "next/server";
+
+export const dynamic = "force-static";
+
+export async function GET() {
+ const supported = [
+ ...new Set([...CONNECT_SUPPORTED_COUNTRIES, ...PAYPAL_SUPPORTED_COUNTRIES]),
+ ];
+ const sorted = supported
+ .sort((a, b) => COUNTRIES[a].localeCompare(COUNTRIES[b]))
+ .map((code) => ({ code, name: COUNTRIES[code] }));
+
+ return NextResponse.json(sorted, {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ "Cache-Control": "public, max-age=86400",
+ },
+ });
+}
diff --git a/apps/web/lib/middleware/embed.ts b/apps/web/lib/middleware/embed.ts
index be5535ed5d..965ece1aa2 100644
--- a/apps/web/lib/middleware/embed.ts
+++ b/apps/web/lib/middleware/embed.ts
@@ -1,14 +1,8 @@
import { NextRequest, NextResponse } from "next/server";
import { parse } from "./utils/parse";
-const PUBLIC_EMBED_PATHS = ["/embed/supported-countries"];
-
export function EmbedMiddleware(req: NextRequest) {
- const { path, searchParamsObj, fullPath } = parse(req);
-
- if (PUBLIC_EMBED_PATHS.includes(path)) {
- return NextResponse.rewrite(new URL(`/app.dub.co${fullPath}`, req.url));
- }
+ const { searchParamsObj, fullPath } = parse(req);
if (searchParamsObj.token) {
return NextResponse.rewrite(new URL(`/app.dub.co${fullPath}`, req.url));