Open source CapCut alternative.
TypeScript
feat(site): localhost serves Donkey Cut by default, Donkey Use under /use
David Led15c8b2232a8
diff --git a/site/src/app/cut/layout.tsx b/site/src/app/cut/layout.tsxindex f5119f34..045d3732 100644--- a/site/src/app/cut/layout.tsx+++ b/site/src/app/cut/layout.tsx@@ -17,7 +17,8 @@ export const metadata: Metadata = {// 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")+// local dev → same mapping as donkeycut.com (base "/app")+// hosted apex → no rewrite, served at /cut/app directly (base "/cut/app")export default async function CutLayout({ children }: { children: ReactNode }) {const base = cutAppBase((await headers()).get("host"));return <CutBaseProvider base={base}>{children}</CutBaseProvider>;diff --git a/site/src/app/cut/page.tsx b/site/src/app/cut/page.tsxindex 72773c32..e09d7e65 100644--- a/site/src/app/cut/page.tsx+++ b/site/src/app/cut/page.tsx@@ -2,7 +2,11 @@ import type { Metadata } from "next";import { headers } from "next/headers";import { CutLanding } from "@/app/cut/_components/landing/CutLanding";-import { DONKEYCUT_CANONICAL, isDonkeycutHost } from "@/cut/lib/hosts";+import {+ DONKEYCUT_CANONICAL,+ isDonkeycutHost,+ isLocalHost,+} from "@/cut/lib/hosts";export const metadata: Metadata = {title: "Donkey Cut — the AI video editor on your Mac",@@ -27,9 +31,11 @@ export const metadata: Metadata = {},};-// The Cut marketing landing: "/" on donkeycut.com, /cut in dev. `root` prefixes-// in-page links to the app so they resolve on either host.+// The Cut marketing landing: "/" on donkeycut.com and in local dev (both+// rewrite "/…" → "/cut/…"), /cut on the hosted apex. `root` prefixes in-page+// links to the app so they resolve on any host.export default async function CutLandingPage() {- const root = isDonkeycutHost((await headers()).get("host")) ? "" : "/cut";+ const host = (await headers()).get("host");+ const root = isDonkeycutHost(host) || isLocalHost(host) ? "" : "/cut";return <CutLanding root={root} />;}diff --git a/site/src/cut/lib/hosts.ts b/site/src/cut/lib/hosts.tsindex 4d7e97be..1670186e 100644--- a/site/src/cut/lib/hosts.ts+++ b/site/src/cut/lib/hosts.ts@@ -6,10 +6,9 @@// 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.+// Local dev is deliberately absent from both sets: localhost gets its own+// proxy branch that mirrors donkeycut.com (Cut at "/", Donkey Use under /use),+// keeping the session cookie same-origin on the one dev origin.export const CUT_HOSTS = new Set(["cut.donkeyuse.com"]);export const DONKEYCUT_HOSTS = new Set(["donkeycut.com", "www.donkeycut.com"]);@@ -32,9 +31,18 @@ export function isDonkeycutHost(host: string | null | undefined): boolean {return DONKEYCUT_HOSTS.has(hostname(host));}+// Local dev serves Donkey Cut by default: the proxy gives localhost the same+// "/…" → "/cut/…" mapping as donkeycut.com, with Donkey Use reachable under+// /use (see src/proxy.ts).+export function isLocalHost(host: string | null | undefined): boolean {+ const name = hostname(host);+ return name === "localhost" || name === "127.0.0.1";+}+// The link base every in-app Cut href is built on (see src/cut/lib/nav.tsx).+// The hosted apex (donkeyuse.com) serves the Cut tree unrewritten at /cut/app.export function cutAppBase(host: string | null | undefined): string {if (isCutHost(host)) return "";- if (isDonkeycutHost(host)) return "/app";+ if (isDonkeycutHost(host) || isLocalHost(host)) return "/app";return "/cut/app";}diff --git a/site/src/proxy.ts b/site/src/proxy.tsindex f62a5376..429a048a 100644--- a/site/src/proxy.ts+++ b/site/src/proxy.ts@@ -5,6 +5,7 @@ import {DONKEYCUT_CANONICAL,isCutHost,isDonkeycutHost,+ isLocalHost,} from "@/cut/lib/hosts";// Cut (the video editor, publicly "Donkey Cut") lives under /cut in this single@@ -13,15 +14,16 @@ import {// serving Donkey://// 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/…" rewrite). "/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.+// Local dev (localhost) mirrors donkeycut.com — Cut is the default product, so+// "/" is the Cut landing and "/app/…" the editor — while Donkey Use stays+// reachable under "/use/…" (stripped to the apex routes). The session cookie+// stays same-origin because everything is served from the one dev origin.//// This file must live in src/ (next to app/) and use the Next 16 `proxy` name;// a root-level middleware.ts is not loaded when the app is under src/.@@ -60,10 +62,23 @@ function cutApi(req: NextRequest): NextResponse {}// 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"];+// "/…" → "/cut/…" rewrite on donkeycut.com. "/install" carries the Mac+// download, and the legal pages are shared verbatim. "/app/settings" is not+// among them: Cut ships its own billing and usage pages under /cut/app/settings,+// which the generic rewrite serves at /app/settings on this host.+const DONKEYCUT_PASSTHROUGH = ["/install", "/privacy", "/terms"];++// Local dev mirrors donkeycut.com (Cut at "/", the editor at "/app/…"), so it+// additionally passes through the auth flows and the notch prototype, which+// only exist on the apex and are exercised from localhost during development.+const LOCAL_PASSTHROUGH = [+ ...DONKEYCUT_PASSTHROUGH,+ "/sign-in",+ "/sign-up",+ "/mac-auth",+ "/cut-auth",+ "/prototype",+];// Whole-segment prefix match, so "/cut" covers "/cut/…" but not "/cut-auth".const underPath = (pathname: string, prefix: string) =>@@ -78,6 +93,25 @@ export function proxy(req: NextRequest) {const host = req.headers.get("host");+ // Local dev serves Donkey Cut by default, like donkeycut.com; Donkey Use+ // stays reachable under /use ("/use/…" → apex "/…").+ if (isLocalHost(host)) {+ if (underPath(pathname, "/use")) {+ const url = req.nextUrl.clone();+ url.pathname = pathname === "/use" ? "/" : pathname.slice("/use".length);+ return NextResponse.rewrite(url);+ }+ if (underPath(pathname, "/cut") || underPath(pathname, "/api")) {+ return NextResponse.next();+ }+ if (LOCAL_PASSTHROUGH.some((p) => underPath(pathname, p))) {+ return NextResponse.next();+ }+ const url = req.nextUrl.clone();+ url.pathname = `/cut${pathname === "/" ? "" : pathname}`;+ return NextResponse.rewrite(url);+ }+if (isDonkeycutHost(host)) {if (host?.split(":")[0] !== "donkeycut.com") {const url = req.nextUrl.clone();