Bot commited on
Commit
ca1682c
·
1 Parent(s): b57b1c4

Robustify eternity POST handler request body parsing

Browse files
Files changed (1) hide show
  1. src/app/api/eternity/route.ts +18 -19
src/app/api/eternity/route.ts CHANGED
@@ -44,25 +44,24 @@ export async function POST(req: NextRequest) {
44
  if (!session?.user) {
45
  return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
46
  }
47
-
48
- const body = await req.json();
49
- const { action, ...payload } = body;
50
-
51
- const backendUrl = getBackendUrl();
52
- const apiKey = process.env.BACKEND_API_KEY || "";
53
-
54
- let targetPath = "";
55
- if (action === "toggle") {
56
- targetPath = "/api/eternity/toggle";
57
- } else if (action === "set-priority") {
58
- targetPath = "/api/eternity/set-priority";
59
- } else if (action === "init") {
60
- targetPath = "/api/eternity/init";
61
- } else {
62
- return NextResponse.json({ error: "Invalid action" }, { status: 400 });
63
- }
64
-
65
  try {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  const res = await fetch(`${backendUrl}${targetPath}`, {
67
  method: "POST",
68
  headers: {
@@ -80,6 +79,6 @@ export async function POST(req: NextRequest) {
80
  const data = await res.json();
81
  return NextResponse.json(data);
82
  } catch (err: any) {
83
- return NextResponse.json({ error: err.message }, { status: 500 });
84
  }
85
  }
 
44
  if (!session?.user) {
45
  return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
46
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  try {
48
+ const body = await req.json();
49
+ const { action, ...payload } = body;
50
+
51
+ const backendUrl = getBackendUrl();
52
+ const apiKey = process.env.BACKEND_API_KEY || "";
53
+
54
+ let targetPath = "";
55
+ if (action === "toggle") {
56
+ targetPath = "/api/eternity/toggle";
57
+ } else if (action === "set-priority") {
58
+ targetPath = "/api/eternity/set-priority";
59
+ } else if (action === "init") {
60
+ targetPath = "/api/eternity/init";
61
+ } else {
62
+ return NextResponse.json({ error: "Invalid action" }, { status: 400 });
63
+ }
64
+
65
  const res = await fetch(`${backendUrl}${targetPath}`, {
66
  method: "POST",
67
  headers: {
 
79
  const data = await res.json();
80
  return NextResponse.json(data);
81
  } catch (err: any) {
82
+ return NextResponse.json({ error: err.message }, { status: 400 });
83
  }
84
  }