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.

edit redirects

Steven Tey7b71af5e6132
diff --git a/lib/constants/index.ts b/lib/constants/index.ts
index fc2ec09235..66dee3c6b2 100644
--- a/lib/constants/index.ts
+++ b/lib/constants/index.ts
@@ -80,7 +80,11 @@ export const APP_DOMAIN_WITH_NGROK =
? "https://preview.dub.co"
: process.env.NGROK_URL;
-export const API_HOSTNAMES = new Set(["api.dub.co", "api.localhost:8888"]);
+export const API_HOSTNAMES = new Set([
+ "api.dub.co",
+ "api.dub.sh",
+ "api.localhost:8888",
+]);
export const ADMIN_HOSTNAMES = new Set([
"admin.dub.co",
diff --git a/lib/middleware/api.ts b/lib/middleware/api.ts
index 70c5556e71..d1edb37e4d 100644
--- a/lib/middleware/api.ts
+++ b/lib/middleware/api.ts
@@ -3,8 +3,8 @@ import { parse } from "#/lib/middleware/utils";
import { HOME_DOMAIN } from "../constants";
export default async function ApiMiddleware(req: NextRequest) {
- const { fullPath } = parse(req);
- if (fullPath === "/") {
+ const { fullPath, domain } = parse(req);
+ if (fullPath === "/" && domain === "api.dub.co") {
return NextResponse.redirect(`${HOME_DOMAIN}/help/article/dub-api`, {
status: 301,
});
diff --git a/next.config.js b/next.config.js
index c1b99e9c7a..39fa6ef2a8 100644
--- a/next.config.js
+++ b/next.config.js
@@ -96,18 +96,6 @@ const nextConfig = {
permanent: true,
statusCode: 301,
},
- {
- source: "/",
- has: [
- {
- type: "host",
- value: "api.dub.sh",
- },
- ],
- destination: "https://api.dub.co",
- permanent: true,
- statusCode: 301,
- },
{
source: "/:path*",
has: [
diff --git a/pages/api/index.ts b/pages/api/index.ts
new file mode 100644
index 0000000000..2c6b6b5420
--- /dev/null
+++ b/pages/api/index.ts
@@ -0,0 +1,31 @@
+import { NextResponse } from "next/server";
+
+export const runtime = "edge";
+
+export default async function handler() {
+ return NextResponse.json({
+ openapi: "3.0.3",
+ info: {
+ title: "Dub.co API",
+ description:
+ "Dub is an open-source link management tool for modern marketing teams to create, share, and track short links.",
+ contact: {
+ email: "[email protected]",
+ name: "Dub.co Support",
+ url: "https://dub.co/help",
+ },
+ version: "0.0.1",
+ },
+ servers: [
+ {
+ url: "https://api.dub.co",
+ description: "Production API",
+ },
+ {
+ url: "https://api.dub.sh",
+ description: "Staging API",
+ },
+ ],
+ paths: {},
+ });
+}
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index 30308a0375..dd80649638 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -98,7 +98,9 @@ export default withLinksAuth(
]).then((results) => results.map((result) => result.value));
if (response === null) {
- return res.status(409).end("Key already exists.");
+ return res
+ .status(409)
+ .end("Duplicate key: this short link already exists.");
}
if (!project && invalidFavicon) {