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.

553 B
Raw Blame
import { NextRequest, NextResponse } from "next/server";
import { parse } from "./utils/parse";

export function ApiMiddleware(req: NextRequest) {
  const { fullPath } = parse(req);

  // redirect to dub.co for /metatags
  if (fullPath.startsWith("/metatags")) {
    return NextResponse.redirect("https://dub.co", {
      status: 301,
    });
  }
  // Note: we don't have to account for paths starting with `/api`
  // since they're automatically excluded via our middleware matcher
  return NextResponse.rewrite(new URL(`/api${fullPath}`, req.url));
}