Skip to content

Commit 5fe7422

Browse files
committed
API endpoint Form submit
1 parent d122e9a commit 5fe7422

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/app/api/form/route.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import { NextResponse } from "next/server";
2+
import { promises as fs } from "fs";
3+
import path from "path";
4+
interface RequestData {
5+
telegramId: string;
6+
discordId: string;
7+
}
8+
const saveSettings = async (data: RequestData): Promise<void> => {
9+
const filePath = path.join(process.cwd(), "src/lib/formData.json");
10+
await fs.writeFile(filePath, JSON.stringify(data, null, 2));
11+
};
212

313
export const POST = async (request: Request) => {
414
const res = await request.json();
5-
15+
await saveSettings(res);
616
return new Response("successful", { status: 200 });
717
};

src/lib/formData.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"telegramId": "12",
3+
"discordId": "12"
4+
}

0 commit comments

Comments
 (0)