-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
163 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { NextResponse } from "next/server"; | ||
|
||
export const runtime = "edge"; | ||
|
||
export async function GET() { | ||
try { | ||
// Construct the URL for the external fetch | ||
const fetchURL = `${process.env.NEXT_PUBLIC_DOMAIN_API}/api/pats`; | ||
|
||
const response = await fetch(fetchURL, { | ||
method: "GET", | ||
headers: { | ||
Authorization: `Bearer ${process.env.DOMAIN_API_KEY}`, | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error("Failed to fetch data"); | ||
} | ||
|
||
const data = await response.json(); | ||
return NextResponse.json(data, { status: 200 }); | ||
} catch (error) { | ||
console.error(error); | ||
return NextResponse.json( | ||
{ error: "Internal Server Error" }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { NextResponse } from "next/server"; | ||
|
||
export const runtime = "edge"; | ||
|
||
export async function PUT(request) { | ||
try { | ||
// Assume the last segment of the URL is the user ID | ||
const patId = request.url.split("/").pop(); | ||
|
||
const requestBody = await request.json(); | ||
|
||
if (!patId) { | ||
throw new Error("Pat ID is required"); | ||
} | ||
|
||
// Construct the URL for the external fetch | ||
const fetchURL = `${process.env.NEXT_PUBLIC_DOMAIN_API}/api/pats/${patId}`; | ||
|
||
const response = await fetch(fetchURL, { | ||
method: "PUT", | ||
headers: { | ||
Authorization: `Bearer ${process.env.DOMAIN_API_KEY}`, | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(requestBody), // Serialize requestBody to JSON | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error("Failed to update data"); | ||
} | ||
|
||
const data = await response.json(); | ||
return NextResponse.json(data, { status: 200 }); | ||
} catch (error) { | ||
return NextResponse.json(error.message, { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters