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.

fix bitly callback hostname

Steven Tey8664d9000c44
diff --git a/app/api/callback/bitly/route.ts b/app/api/callback/bitly/route.ts
index 271d3f9d6c..aaa78c6165 100644
--- a/app/api/callback/bitly/route.ts
+++ b/app/api/callback/bitly/route.ts
@@ -18,14 +18,15 @@ export async function GET(req: Request) {
body: `client_id=${process.env.NEXT_PUBLIC_BITLY_CLIENT_ID}&client_secret=${process.env.BITLY_CLIENT_SECRET}&code=${code}&redirect_uri=${process.env.NEXT_PUBLIC_BITLY_REDIRECT_URI}`,
}).then((r) => r.text());
+ const hostname =
+ process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
+ ? "https://app.dub.sh"
+ : process.env.NEXT_PUBLIC_VERCEL_ENV === "preview"
+ ? "https://preview.dub.sh"
+ : "http://app.localhost:3000";
+
if (!response || response.includes("error")) {
- return NextResponse.redirect(
- `${
- process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
- ? "https://app.dub.sh/"
- : "http://app.localhost:3000/"
- }`,
- );
+ return NextResponse.redirect(hostname);
}
const params = new URLSearchParams(response);
@@ -46,10 +47,6 @@ export async function GET(req: Request) {
// redirect to project page with import query param
return NextResponse.redirect(
- `${
- process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
- ? "https://app.dub.sh/"
- : "http://app.localhost:3000/"
- }${project ? `${project.slug}?import=bitly` : ""}`,
+ `${hostname}${project ? `/${project.slug}?import=bitly` : ""}`,
);
}