Skip to content

Commit d4ba62d

Browse files
Temporarily disable all services and redirect to manaflow.com (#1779)
* Temporarily disable all API endpoints and redirect traffic to manaflow.com Controlled by a single MANAFLOW_DEPRECATED flag. When true: - Next.js middleware redirects all non-manaflow.com domains (cmux.sh, 0github.com, preview.new, cloudrouter.dev) to manaflow.com via 307 - All /api/*, /iiiii/* (PostHog), /mtrerr (Sentry) routes return 503 - Hono catch-all, Anthropic proxy, and PR review routes have backup guards - Cloudflare edge router redirects all *.cmux.sh traffic to manaflow.com - Convex HTTP routes return 503 via d() wrapper - Convex crons (Morph maintenance, warm pool cleanup) disabled - PostHog proxy rewrites in next.config.ts disabled To restore: set MANAFLOW_DEPRECATED = false in apps/www/lib/deprecation.ts, edge-router/src/index.ts, and packages/convex/convex/http.ts. Uncomment crons in packages/convex/convex/crons.ts. Search "MANAFLOW_DEPRECATED" to find all references. * Fix httpAction import and middleware matcher - Import httpAction from ./_generated/server (not convex/server) - Add /api/:path* to middleware matcher so deprecation guard actually runs - Also block /api root path (not just /api/) * Move deprecation logic into proxy.ts (Next.js 16 compatibility) Next.js 16 uses proxy.ts instead of middleware.ts. Having both files causes a build error. Merged deprecation guard into proxy.ts and made the config export a static object (required by Next.js). --------- Co-authored-by: Lawrence Chen <lawrencecchen@users.noreply.github.com>
1 parent 590cbad commit d4ba62d

9 files changed

Lines changed: 206 additions & 90 deletions

File tree

apps/edge-router/src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,20 @@ function rewriteLoopbackRedirect(
637637
});
638638
}
639639

640+
// =============================================================================
641+
// TEMPORARY DEPRECATION FLAG
642+
// Set to false to restore normal edge-router operation.
643+
// Search for "MANAFLOW_DEPRECATED" across the repo to find all references.
644+
// =============================================================================
645+
const MANAFLOW_DEPRECATED = true;
646+
640647
export default {
641648
async fetch(request: Request): Promise<Response> {
649+
// When deprecated, redirect everything to manaflow.com
650+
if (MANAFLOW_DEPRECATED) {
651+
return Response.redirect("https://manaflow.com", 307);
652+
}
653+
642654
const url = new URL(request.url);
643655
const host = url.hostname.toLowerCase();
644656

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1+
import { MANAFLOW_DEPRECATED } from "@/lib/deprecation";
12
import { app } from "@/lib/hono-app";
23
import { handle } from "hono/vercel";
4+
import { NextResponse } from "next/server";
35

4-
export const GET = handle(app);
5-
export const POST = handle(app);
6-
export const PUT = handle(app);
7-
export const DELETE = handle(app);
8-
export const PATCH = handle(app);
9-
export const OPTIONS = handle(app);
6+
function blocked() {
7+
return NextResponse.json(
8+
{ error: "Manaflow is temporarily unavailable" },
9+
{ status: 503 },
10+
);
11+
}
12+
13+
const honoGet = handle(app);
14+
const honoPost = handle(app);
15+
const honoPut = handle(app);
16+
const honoDelete = handle(app);
17+
const honoPatch = handle(app);
18+
const honoOptions = handle(app);
19+
20+
export const GET = MANAFLOW_DEPRECATED ? blocked : honoGet;
21+
export const POST = MANAFLOW_DEPRECATED ? blocked : honoPost;
22+
export const PUT = MANAFLOW_DEPRECATED ? blocked : honoPut;
23+
export const DELETE = MANAFLOW_DEPRECATED ? blocked : honoDelete;
24+
export const PATCH = MANAFLOW_DEPRECATED ? blocked : honoPatch;
25+
export const OPTIONS = MANAFLOW_DEPRECATED ? blocked : honoOptions;

apps/www/app/api/anthropic/v1/messages/route.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MANAFLOW_DEPRECATED } from "@/lib/deprecation";
12
import { verifyTaskRunToken, type TaskRunTokenPayload } from "@cmux/shared";
23
import { CMUX_ANTHROPIC_PROXY_PLACEHOLDER_API_KEY } from "@cmux/shared/utils/anthropic";
34
import { env } from "@/lib/utils/www-env";
@@ -84,6 +85,13 @@ function getSource(request: NextRequest): AnthropicProxySource {
8485
}
8586

8687
export async function POST(request: NextRequest) {
88+
if (MANAFLOW_DEPRECATED) {
89+
return NextResponse.json(
90+
{ error: "Manaflow is temporarily unavailable" },
91+
{ status: 503 },
92+
);
93+
}
94+
8795
const startTime = Date.now();
8896
const source = getSource(request);
8997
let tokenPayload: TaskRunTokenPayload | null = null;

apps/www/app/api/pr-review/simple/route.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MANAFLOW_DEPRECATED } from "@/lib/deprecation";
12
import { NextRequest, NextResponse } from "next/server";
23

34
import { stackServerApp } from "@/lib/utils/stack";
@@ -42,6 +43,13 @@ function parsePrNumber(raw: string | null): number | null {
4243
}
4344

4445
export async function GET(request: NextRequest) {
46+
if (MANAFLOW_DEPRECATED) {
47+
return NextResponse.json(
48+
{ error: "Manaflow is temporarily unavailable" },
49+
{ status: 503 },
50+
);
51+
}
52+
4553
try {
4654
const { searchParams } = request.nextUrl;
4755
const repoFullName = parseRepoFullName(searchParams.get("repoFullName"));

apps/www/lib/deprecation.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// =============================================================================
2+
// TEMPORARY DEPRECATION FLAG
3+
//
4+
// Set to `false` to restore normal operation. When `true`:
5+
// - Next.js middleware redirects all non-manaflow.com traffic to manaflow.com
6+
// - All /api/* endpoints return 503
7+
// - Edge router (Cloudflare Worker) redirects *.cmux.sh to manaflow.com
8+
// - Convex HTTP routes return 503
9+
//
10+
// To fully remove: delete this file, revert middleware.ts to proxy.ts logic,
11+
// revert edge-router/src/index.ts, and revert convex/http.ts guards.
12+
// Search for "MANAFLOW_DEPRECATED" across the repo to find all references.
13+
// =============================================================================
14+
15+
export const MANAFLOW_DEPRECATED = true;

apps/www/next.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { withSentryConfig } from "@sentry/nextjs";
22
import type { NextConfig } from "next";
33
import { SENTRY_RELEASE } from "./lib/sentry-release";
4+
import { MANAFLOW_DEPRECATED } from "./lib/deprecation";
45

56
const nextConfig: NextConfig = {
67
serverExternalPackages: ["morphcloud", "ssh2", "node-ssh", "cpu-features"],
@@ -14,6 +15,11 @@ const nextConfig: NextConfig = {
1415
"refractor",
1516
],
1617
async rewrites() {
18+
// TEMPORARY DEPRECATION: PostHog proxy rewrites disabled to prevent analytics API calls.
19+
// To restore: remove the MANAFLOW_DEPRECATED guard.
20+
if (MANAFLOW_DEPRECATED) {
21+
return [];
22+
}
1723
return [
1824
{
1925
source: "/iiiii/static/:path*",

apps/www/proxy.ts

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NextResponse } from "next/server";
22
import type { NextRequest } from "next/server";
3+
import { MANAFLOW_DEPRECATED } from "@/lib/deprecation";
34
import { env } from "@/lib/utils/www-env";
45

56
/**
@@ -25,7 +26,42 @@ function hasStackCookie(
2526
);
2627
}
2728

29+
function deprecationProxy(request: NextRequest) {
30+
const { pathname } = request.nextUrl;
31+
const hostname = request.nextUrl.hostname;
32+
33+
// Block ALL API routes, analytics proxies, and error tunnels
34+
if (
35+
pathname === "/api" ||
36+
pathname.startsWith("/api/") ||
37+
pathname.startsWith("/iiiii/") ||
38+
pathname.startsWith("/mtrerr")
39+
) {
40+
return NextResponse.json(
41+
{ error: "Manaflow is temporarily unavailable" },
42+
{ status: 503 }
43+
);
44+
}
45+
46+
// manaflow.com: show the existing landing page, don't redirect to itself
47+
if (hostname === "manaflow.com" || hostname === "www.manaflow.com") {
48+
if (pathname === "/") {
49+
return NextResponse.rewrite(new URL("/manaflow", request.url));
50+
}
51+
// Let the manaflow landing page and its assets render
52+
return NextResponse.next();
53+
}
54+
55+
// Everything else (cmux.sh, 0github.com, preview.new, cloudrouter.dev, etc.)
56+
// gets a temporary redirect to manaflow.com
57+
return NextResponse.redirect("https://manaflow.com", 307);
58+
}
59+
2860
export function proxy(request: NextRequest) {
61+
if (MANAFLOW_DEPRECATED) {
62+
return deprecationProxy(request);
63+
}
64+
2965
const { pathname } = request.nextUrl;
3066
const hostname = request.nextUrl.hostname;
3167

@@ -108,26 +144,16 @@ export function proxy(request: NextRequest) {
108144
return NextResponse.next();
109145
}
110146

147+
// TEMPORARY DEPRECATION: matcher includes /api/* so the deprecation guard runs.
148+
// To restore, replace with the original matcher that excludes api paths:
149+
// "/:owner/:repo/pull/:number",
150+
// "/:owner/:repo/compare/:path*",
151+
// "/((?!api|_next/static|_next/image|favicon.ico).*)",
111152
export const config = {
112153
matcher: [
113-
/*
114-
* Match all PR review and comparison pages:
115-
* - /:owner/:repo/pull/:number
116-
* - /:owner/:repo/compare/...
117-
* But exclude:
118-
* - /api routes
119-
* - /_next (Next.js internals)
120-
* - Static files
121-
*/
122-
"/:owner/:repo/pull/:number",
123-
"/:owner/:repo/compare/:path*",
124-
/*
125-
* Match all request paths except for the ones starting with:
126-
* - api (API routes)
127-
* - _next/static (static files)
128-
* - _next/image (image optimization files)
129-
* - favicon.ico (favicon file)
130-
*/
131-
"/((?!api|_next/static|_next/image|favicon.ico).*)",
154+
"/api/:path*",
155+
"/iiiii/:path*",
156+
"/mtrerr",
157+
"/((?!_next/static|_next/image|favicon.ico).*)",
132158
],
133159
};

packages/convex/convex/crons.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
import { cronJobs } from "convex/server";
2-
import { internal } from "./_generated/api";
2+
// import { internal } from "./_generated/api";
33

44
const crons = cronJobs();
55

6+
// =============================================================================
7+
// TEMPORARY DEPRECATION: All crons disabled.
8+
// To restore: uncomment the import above and all cron registrations below.
9+
// Search for "MANAFLOW_DEPRECATED" across the repo to find all references.
10+
// =============================================================================
11+
612
// Pause Morph instances older than 20 hours
713
// Runs daily at 4 AM Pacific Time
8-
// 4 AM PST = 12:00 UTC (during standard time)
9-
// 4 AM PDT = 11:00 UTC (during daylight saving)
10-
// Using 12:00 UTC means it runs at 4 AM PST or 5 AM PDT
11-
crons.daily(
12-
"pause old morph instances",
13-
{ hourUTC: 12, minuteUTC: 0 },
14-
internal.morphInstanceMaintenance.pauseOldMorphInstances
15-
);
14+
// crons.daily(
15+
// "pause old morph instances",
16+
// { hourUTC: 12, minuteUTC: 0 },
17+
// internal.morphInstanceMaintenance.pauseOldMorphInstances
18+
// );
1619

1720
// Stop (delete) Morph instances that have been paused for more than 2 weeks
1821
// Runs daily at 13:00 UTC (~5-6 AM Pacific depending on DST)
19-
crons.daily(
20-
"stop old morph instances",
21-
{ hourUTC: 13, minuteUTC: 0 },
22-
internal.morphInstanceMaintenance.stopOldMorphInstances
23-
);
22+
// crons.daily(
23+
// "stop old morph instances",
24+
// { hourUTC: 13, minuteUTC: 0 },
25+
// internal.morphInstanceMaintenance.stopOldMorphInstances
26+
// );
2427

2528
// Clean up stale warm pool entries daily at 11:30 UTC
26-
crons.daily(
27-
"cleanup warm pool",
28-
{ hourUTC: 11, minuteUTC: 30 },
29-
internal.warmPoolMaintenance.cleanupWarmPool
30-
);
29+
// crons.daily(
30+
// "cleanup warm pool",
31+
// { hourUTC: 11, minuteUTC: 30 },
32+
// internal.warmPoolMaintenance.cleanupWarmPool
33+
// );
3134

3235
export default crons;

0 commit comments

Comments
 (0)