Skip to content

Open source CapCut alternative.

TypeScript

feat(site): serve Donkey Cut on donkeycut.com with the app under /app

David Le0993eedf3b10
diff --git a/site/src/app/cut/(home)/layout.tsx b/site/src/app/cut/app/(home)/layout.tsx
similarity index 100%
rename from site/src/app/cut/(home)/layout.tsx
rename to site/src/app/cut/app/(home)/layout.tsx
diff --git a/site/src/app/cut/(home)/library/page.tsx b/site/src/app/cut/app/(home)/library/page.tsx
similarity index 100%
rename from site/src/app/cut/(home)/library/page.tsx
rename to site/src/app/cut/app/(home)/library/page.tsx
diff --git a/site/src/app/cut/(home)/page.tsx b/site/src/app/cut/app/(home)/page.tsx
similarity index 100%
rename from site/src/app/cut/(home)/page.tsx
rename to site/src/app/cut/app/(home)/page.tsx
diff --git a/site/src/app/cut/app/layout.tsx b/site/src/app/cut/app/layout.tsx
new file mode 100644
index 00000000..9a8c0516
--- /dev/null
+++ b/site/src/app/cut/app/layout.tsx
@@ -0,0 +1,17 @@
+import type { ReactNode } from "react";
+
+import { AppSurfaceBackground } from "@/app/app/_components/AppSurfaceBackground";
+
+// The Cut app (projects home, library, editor) renders on the same white
+// product surface as Donkey's /app, not the cream marketing background of the
+// landing page that lives one segment up. AppSurfaceBackground paints the root
+// html white so the cream does not show through the overscroll area, and
+// font-system matches the /app system font stack.
+export default function CutAppLayout({ children }: { children: ReactNode }) {
+ return (
+ <div className="min-h-screen bg-white font-system text-foreground antialiased">
+ <AppSurfaceBackground />
+ {children}
+ </div>
+ );
+}
diff --git a/site/src/app/cut/p/[id]/page.tsx b/site/src/app/cut/app/p/[id]/page.tsx
similarity index 100%
rename from site/src/app/cut/p/[id]/page.tsx
rename to site/src/app/cut/app/p/[id]/page.tsx
diff --git a/site/src/app/cut/layout.tsx b/site/src/app/cut/layout.tsx
index 6b92d2d2..f5119f34 100644
--- a/site/src/app/cut/layout.tsx
+++ b/site/src/app/cut/layout.tsx
@@ -2,8 +2,7 @@ import type { Metadata } from "next";
import type { ReactNode } from "react";
import { headers } from "next/headers";
-import { AppSurfaceBackground } from "@/app/app/_components/AppSurfaceBackground";
-import { isCutHost } from "@/cut/lib/hosts";
+import { cutAppBase } from "@/cut/lib/hosts";
import { CutBaseProvider } from "@/cut/lib/nav";
export const metadata: Metadata = {
@@ -11,20 +10,15 @@ export const metadata: Metadata = {
description: "A video editor that does all its work on your Mac.",
};
-// Cut (the video editor) renders on the same white product surface as Donkey's
-// /app, not the cream marketing background. AppSurfaceBackground paints the root
-// html white so the cream landing background does not show through the overscroll
-// area, and font-system matches the /app system font stack.
+// This layout only resolves the app link base; surface styling belongs to the
+// children. The landing page at /cut renders on the cream marketing background,
+// while the app subtree under /cut/app paints its own white product surface.
+//
+// The app's routes live under /cut/app/*. Per host they are served as:
+// cut.donkeyuse.com → proxy rewrites "/…" → "/cut/app/…" (base "")
+// donkeycut.com → proxy rewrites "/app/…" → "/cut/app/…" (base "/app")
+// local dev (apex) → no rewrite, opened at /cut/app directly (base "/cut/app")
export default async function CutLayout({ children }: { children: ReactNode }) {
- // The app's routes live under /cut/*. On the cut.* production host a proxy
- // rewrite serves them at the root, so links are root-relative (base ""). In
- // local dev the app is opened at /cut on the apex — same origin as the session
- // cookie — so links carry the "/cut" base. Resolve it once from the host.
- const base = isCutHost((await headers()).get("host")) ? "" : "/cut";
- return (
- <div className="min-h-screen bg-white font-system text-foreground antialiased">
- <AppSurfaceBackground />
- <CutBaseProvider base={base}>{children}</CutBaseProvider>
- </div>
- );
+ const base = cutAppBase((await headers()).get("host"));
+ return <CutBaseProvider base={base}>{children}</CutBaseProvider>;
}
diff --git a/site/src/cut/lib/hosts.ts b/site/src/cut/lib/hosts.ts
index b116e10b..4d7e97be 100644
--- a/site/src/cut/lib/hosts.ts
+++ b/site/src/cut/lib/hosts.ts
@@ -1,13 +1,40 @@
-// Hosts that serve the Cut app at their root. On these, the src/proxy.ts rewrite
-// maps "/…" to the app's real "/cut/…" routes, so links stay clean ("/p/[id]").
+// Cut is served from two production hosts, mapped by src/proxy.ts onto the
+// real routes under /cut:
//
-// Local dev is deliberately absent: there Cut is served from the apex under
-// /cut, so its session cookie is same-origin. A cookie set on `localhost` never
-// reaches a `cut.localhost` subdomain in Chrome, so the subdomain can't hold a
-// session — the /cut path on the apex is what dev uses instead.
+// donkeycut.com the Cut product domain — marketing landing at "/",
+// the app at "/app/…" (rewritten to /cut/app/…).
+// cut.donkeyuse.com the legacy host — the app at its root ("/", "/p/[id]",
+// rewritten to /cut/app/…), unchanged for existing links.
+//
+// Local dev is deliberately absent from both sets: there Cut is served from the
+// apex under /cut, so its session cookie is same-origin. A cookie set on
+// `localhost` never reaches a `cut.localhost` subdomain in Chrome, so a
+// subdomain can't hold a session — the /cut path on the apex is what dev uses.
export const CUT_HOSTS = new Set(["cut.donkeyuse.com"]);
+export const DONKEYCUT_HOSTS = new Set(["donkeycut.com", "www.donkeycut.com"]);
+
+export const DONKEYCUT_CANONICAL = "https://donkeycut.com";
+
+// The apex origin that owns auth (Google OAuth redirect_uri, session minting).
+// donkeycut.com signs in by bouncing through it — see /cut-auth.
+export const DONKEY_APEX_ORIGIN = "https://donkeyuse.com";
+
+function hostname(host: string | null | undefined): string {
+ return host ? host.split(":")[0] : "";
+}
+
export function isCutHost(host: string | null | undefined): boolean {
- if (!host) return false;
- return CUT_HOSTS.has(host.split(":")[0]);
+ return CUT_HOSTS.has(hostname(host));
+}
+
+export function isDonkeycutHost(host: string | null | undefined): boolean {
+ return DONKEYCUT_HOSTS.has(hostname(host));
+}
+
+// The link base every in-app Cut href is built on (see src/cut/lib/nav.tsx).
+export function cutAppBase(host: string | null | undefined): string {
+ if (isCutHost(host)) return "";
+ if (isDonkeycutHost(host)) return "/app";
+ return "/cut/app";
}
diff --git a/site/src/cut/lib/nav.tsx b/site/src/cut/lib/nav.tsx
index a8a2d35c..2b503992 100644
--- a/site/src/cut/lib/nav.tsx
+++ b/site/src/cut/lib/nav.tsx
@@ -2,12 +2,12 @@
import { createContext, useContext, type ReactNode } from "react";
-// The Cut app's routes live under /cut/*. On the cut.* production host a proxy
-// rewrite (src/proxy.ts) serves them at the root, so links are root-relative
-// (base ""). In local dev the app is served from the apex under /cut so its
-// session cookie is same-origin, and links carry the "/cut" base. The base is
-// resolved on the server from the request host (see the cut layout) and handed
-// to the client here.
+// The Cut app's routes live under /cut/app/*. A proxy rewrite (src/proxy.ts)
+// serves them at "/…" on cut.donkeyuse.com (base "") and at "/app/…" on
+// donkeycut.com (base "/app"). In local dev the app is served from the apex
+// under /cut/app so its session cookie is same-origin, and links carry the
+// full "/cut/app" base. The base is resolved on the server from the request
+// host (see the cut layout) and handed to the client here.
const CutBaseContext = createContext("");
export function CutBaseProvider({ base, children }: { base: string; children: ReactNode }) {
diff --git a/site/src/proxy.ts b/site/src/proxy.ts
index 3ff73bf3..f62a5376 100644
--- a/site/src/proxy.ts
+++ b/site/src/proxy.ts
@@ -1,16 +1,26 @@
import { NextResponse, type NextRequest } from "next/server";
import { allowedOrigin, corsHeaders, preflightHeaders } from "@/cut/server/cors";
-import { isCutHost } from "@/cut/lib/hosts";
+import {
+ DONKEYCUT_CANONICAL,
+ isCutHost,
+ isDonkeycutHost,
+} from "@/cut/lib/hosts";
-// Cut (the video editor, publicly "Donkey Cut") is served on the
-// cut.donkeyuse.com subdomain, but its routes live under /cut in this single
-// site app. For requests on the Cut host we rewrite page paths to /cut/* so
-// Cut's root-relative links (/, /library, /p/[id]) resolve to its routes, while
-// the apex host keeps serving Donkey.
+// Cut (the video editor, publicly "Donkey Cut") lives under /cut in this single
+// site app: the marketing landing at /cut and the app under /cut/app. The proxy
+// maps its two production hosts onto that tree while the apex host keeps
+// serving Donkey:
//
-// Local dev is not a Cut host: the editor is opened at localhost:3000/cut/… so
-// its session cookie is same-origin, and its links carry the "/cut" base
+// donkeycut.com "/" → landing, "/app/…" → editor app (generic
+// "/…" → "/cut/…" rewrite). "/app/settings", "/install",
+// and the legal pages pass through so the shared apex
+// routes serve them same-host. www. 308s to the apex.
+// cut.donkeyuse.com legacy host, unchanged URLs: "/…" → "/cut/app/…" so
+// "/", "/library", "/p/[id]" keep working.
+//
+// Local dev is neither host: the editor is opened at localhost:3000/cut/… so
+// its session cookie is same-origin, and its links carry the "/cut/app" base
// directly (see src/cut/lib/nav.tsx), needing no rewrite.
//
// This file must live in src/ (next to app/) and use the Next 16 `proxy` name;
@@ -49,26 +59,63 @@ function cutApi(req: NextRequest): NextResponse {
return res;
}
+// Paths served by shared apex routes that must not be captured by the generic
+// "/…" → "/cut/…" rewrite on donkeycut.com. "/app/settings" is the shared
+// account surface (the rest of "/app" is the Cut projects home), "/install"
+// carries the Mac download, and the legal pages are shared verbatim.
+const DONKEYCUT_PASSTHROUGH = ["/app/settings", "/install", "/privacy", "/terms"];
+
+// Whole-segment prefix match, so "/cut" covers "/cut/…" but not "/cut-auth".
+const underPath = (pathname: string, prefix: string) =>
+ pathname === prefix || pathname.startsWith(`${prefix}/`);
+
+const passesThrough = (pathname: string) =>
+ DONKEYCUT_PASSTHROUGH.some((p) => underPath(pathname, p));
+
export function proxy(req: NextRequest) {
const { pathname } = req.nextUrl;
if (isCutApi(pathname)) return cutApi(req);
- if (!isCutHost(req.headers.get("host"))) return NextResponse.next();
+ const host = req.headers.get("host");
+
+ if (isDonkeycutHost(host)) {
+ if (host?.split(":")[0] !== "donkeycut.com") {
+ const url = req.nextUrl.clone();
+ return NextResponse.redirect(
+ `${DONKEYCUT_CANONICAL}${pathname}${url.search}`,
+ 308,
+ );
+ }
+ if (underPath(pathname, "/cut") || underPath(pathname, "/api")) {
+ return NextResponse.next();
+ }
+ if (passesThrough(pathname)) return NextResponse.next();
+ const url = req.nextUrl.clone();
+ url.pathname =
+ pathname === "/sitemap.xml"
+ ? "/cut/sitemap.xml"
+ : `/cut${pathname === "/" ? "" : pathname}`;
+ return NextResponse.rewrite(url);
+ }
+
+ if (!isCutHost(host)) return NextResponse.next();
- if (pathname.startsWith("/cut") || pathname.startsWith("/api")) {
+ if (underPath(pathname, "/cut") || underPath(pathname, "/api")) {
return NextResponse.next();
}
const url = req.nextUrl.clone();
- url.pathname = `/cut${pathname === "/" ? "" : pathname}`;
+ url.pathname = `/cut/app${pathname === "/" ? "" : pathname}`;
return NextResponse.rewrite(url);
}
export const config = {
// Page routes (skip Next internals and files with an extension) plus every
// Cut API path — including media/export files with extensions — so the
- // hosted 404 and local CORS above cover all of them.
+ // hosted 404 and local CORS above cover all of them. "/sitemap.xml" is
+ // matched explicitly so donkeycut.com can serve its own sitemap.
matcher: [
"/((?!_next/|.*\\..*).*)",
"/api/cut/:path*",
+ "/sitemap.xml",
],
};