MCPcopy Create free account
hub / github.com/CodeWithHarry/Sigma-Web-Dev-Course / POST

Function POST

Video 136/bitlinks/app/api/generate/route.js:4–23  ·  view source on GitHub ↗
(request)

Source from the content-addressed store, hash-verified

2import clientPromise from "@/lib/mongodb"
3
4export async function POST(request) {
5
6 const body = await request.json()
7 const client = await clientPromise;
8 const db = client.db("bitlinks")
9 const collection = db.collection("url")
10
11 // Check if the short url exists
12 const doc = await collection.findOne({shorturl: body.shorturl})
13 if(doc){
14 return Response.json({success: false, error: true, message: 'URL already exists!' })
15 }
16
17 const result = await collection.insertOne({
18 url: body.url,
19 shorturl: body.shorturl
20 })
21
22 return Response.json({success: true, error: false, message: 'URL Generated Successfully' })
23 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected