9router/src/app/api/shutdown/route.js

25 lines
693 B
JavaScript
Raw Normal View History

2026-01-04 21:58:59 -05:00
import { NextResponse } from "next/server";
import { headers } from "next/headers";
2026-01-04 21:58:59 -05:00
export async function POST() {
if (process.env.NODE_ENV === "production") {
return NextResponse.json({ success: false, message: "Not allowed in production" }, { status: 403 });
}
const secret = process.env.SHUTDOWN_SECRET;
const authorization = headers().get("authorization");
if (!secret || authorization !== `Bearer ${secret}`) {
return NextResponse.json({ success: false, message: "Unauthorized" }, { status: 401 });
}
2026-01-04 21:58:59 -05:00
const response = NextResponse.json({ success: true, message: "Shutting down..." });
setTimeout(() => {
process.exit(0);
}, 500);
return response;
}