Skip to content

Commit a00d3a7

Browse files
feat: add Neon database integration and form submission functionality
1 parent a0b4b31 commit a00d3a7

File tree

5 files changed

+173
-21
lines changed

5 files changed

+173
-21
lines changed

package-lock.json

Lines changed: 133 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"dependencies": {
1212
"@clerk/clerk-sdk-node": "^5.1.6",
13+
"@neondatabase/serverless": "^1.0.0",
1314
"@types/node-fetch": "^2.6.12",
1415
"next": "15.1.6",
1516
"node-fetch": "^3.3.2",

src/app/api/submit/route.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
1-
// import { NextResponse } from 'next/server';
2-
3-
// export async function POST(req: Request) {
4-
// try {
5-
// const { name, email } = await req.json();
6-
7-
// if (!name || !email) {
8-
// return NextResponse.json({ message: 'Name and Email are required' }, { status: 400 });
9-
// }
10-
11-
// return NextResponse.json({ message: `Thank you, ${name}!` });
12-
// } catch {
13-
// return NextResponse.json({ message: 'Server error' }, { status: 500 });
14-
// }
15-
// }
16-
17-
import { NextResponse } from 'next/server';
1+
import { NextResponse } from "next/server";
2+
// import { neon } from "@neondatabase/serverless";
183

194
export async function POST(req: Request) {
205
try {
216
const { name, email } = await req.json();
227

238
if (!name || !email) {
24-
return NextResponse.json({ message: 'Name and Email are required' }, { status: 400 });
9+
return NextResponse.json(
10+
{ message: "Name and Email are required" },
11+
{ status: 400 }
12+
);
2513
}
2614

27-
return NextResponse.json({ message: `Hello ${name}, your form has been submitted successfully!` });
15+
// No database insertion here, just respond
16+
return NextResponse.json({
17+
message: `Hello ${name}, your form has been submitted successfully!`,
18+
});
2819
} catch {
29-
return NextResponse.json({ message: 'Internal server error' }, { status: 500 });
20+
return NextResponse.json(
21+
{ message: "Internal server error" },
22+
{ status: 500 }
23+
);
3024
}
3125
}

src/app/page.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
1-
import Link from 'next/link';
1+
import Link from "next/link";
2+
import { neon } from "@neondatabase/serverless";
23

34
export default function Home() {
5+
async function create(formData: FormData) {
6+
"use server";
7+
// Connect to the Neon database
8+
const sql = neon(`${process.env.DATABASE_URL}`);
9+
const comment = formData.get("comment");
10+
// Insert the comment from the form into the Postgres database using tagged template literal
11+
await sql`INSERT INTO comments (comment) VALUES (${comment})`;
12+
}
13+
414
return (
515
<div className="container">
616
<h1>Welcome to Next.js + Playwright</h1>
717
<Link href="/form">Go to Form</Link>
18+
<form action={create} style={{ marginTop: "2rem" }}>
19+
<input
20+
type="text"
21+
placeholder="write a comment"
22+
name="comment"
23+
required
24+
style={{ marginRight: "0.5rem" }}
25+
/>
26+
<button type="submit">Submit</button>
27+
</form>
828
</div>
929
);
1030
}

tests/test-results/.last-run.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"status": "passed",
3+
"failedTests": []
4+
}

0 commit comments

Comments
 (0)