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.

Rebrand

Steven Tey44543a4aa7a2
diff --git a/lib/constants/index.ts b/lib/constants/index.ts
index ae669fb33c..8457fe2f94 100644
--- a/lib/constants/index.ts
+++ b/lib/constants/index.ts
@@ -56,6 +56,7 @@ export const APP_HOSTNAMES = new Set([
"localhost:8888",
"localhost",
"app.dub.sh",
+ "app.dub.co",
"preview.dub.sh",
]);
@@ -73,6 +74,12 @@ export const APP_DOMAIN_WITH_NGROK =
? "https://preview.dub.sh"
: process.env.NGROK_URL;
+export const API_HOSTNAMES = new Set([
+ "api.dub.co",
+ "api.dub.sh",
+ "api.localhost:8888",
+]);
+
export const DEFAULT_REDIRECTS = {
home: "https://dub.sh",
dub: "https://dub.sh",
diff --git a/middleware.ts b/middleware.ts
index e4e5761112..37cdb90af7 100644
--- a/middleware.ts
+++ b/middleware.ts
@@ -1,5 +1,9 @@
import { NextFetchEvent, NextRequest, NextResponse } from "next/server";
-import { APP_HOSTNAMES, DEFAULT_REDIRECTS } from "#/lib/constants";
+import {
+ API_HOSTNAMES,
+ APP_HOSTNAMES,
+ DEFAULT_REDIRECTS,
+} from "#/lib/constants";
import {
AppMiddleware,
ApiMiddleware,
@@ -28,21 +32,17 @@ export const config = {
export default async function middleware(req: NextRequest, ev: NextFetchEvent) {
const { domain, path, key } = parse(req);
- // for App (e.g. app.dub.sh)
+ // for App
if (APP_HOSTNAMES.has(domain)) {
return AppMiddleware(req);
}
- // for API (api.dub.co, api.dub.sh, and api.localhost:8888)
- if (
- domain === "api.dub.co" ||
- domain === "api.dub.sh" ||
- domain === "api.localhost:8888"
- ) {
+ // for API
+ if (API_HOSTNAMES.has(domain)) {
return ApiMiddleware(req);
}
- // for Admin (admin.dub.sh and admin.localhost:8888)
+ // for Admin
if (domain === "admin.dub.sh" || domain === "admin.localhost:8888") {
return AdminMiddleware(req);
}
diff --git a/next.config.js b/next.config.js
index 770155e056..1044585538 100644
--- a/next.config.js
+++ b/next.config.js
@@ -42,6 +42,32 @@ const nextConfig = {
},
];
},
+ async redirects() {
+ return [
+ {
+ source: "/",
+ has: [
+ {
+ type: "host",
+ value: "app.dub.sh",
+ },
+ ],
+ destination: "https://app.dub.co",
+ permanent: true,
+ },
+ {
+ source: "/:path*",
+ has: [
+ {
+ type: "host",
+ value: "app.dub.sh",
+ },
+ ],
+ destination: "https://app.dub.co/:path*",
+ permanent: true,
+ },
+ ];
+ },
};
module.exports = withContentlayer(nextConfig);