added api route

This commit is contained in:
Chad Bailey
2025-02-06 01:20:35 +00:00
parent 5f9e24791e
commit fb0a1548ab
8 changed files with 2140 additions and 64 deletions

View File

@@ -0,0 +1,27 @@
// [POST] /api
export async function POST(request: Request) {
const params = await request.json();
console.log("in POST, params is ", params)
const url = process.env.BOT_START_URL || "http://localhost:7860"
const req = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.PCC_API_KEY}`,
},
body: JSON.stringify(params),
});
const res = await req.json();
if (req.status !== 200) {
return Response.json(res, { status: req.status });
}
console.log({res});
return Response.json(res);
}
export async function GET(request: Request) {
return Response.json({message: "Hello World"});
}

View File

@@ -27,22 +27,26 @@ export default function Call() {
// Create a new room for the story session
try {
const response = await fetch("/", {
console.log("POSTing to /api")
const response = await fetch("/api", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"createDailyRoom": true
})
});
const { room_url, token } = await response.json();
const {dailyRoom, dailyToken} = await response.json();
console.log({dailyRoom, dailyToken})
// Keep a reference to the room url for later
setRoom(room_url);
setRoom(dailyRoom);
// Join the WebRTC session
await daily.join({
url: room_url,
token,
url: dailyRoom,
token: dailyToken,
videoSource: false,
startAudioOff: true,
});

View File

@@ -0,0 +1,3 @@
SITE_URL=
PCC_API_KEY=
BOT_START_URL=

File diff suppressed because it is too large Load Diff

View File

@@ -33,6 +33,7 @@
"eslint-config-next": "14.1.4",
"postcss": "^8.4.47",
"tailwindcss": "^3.4.13",
"typescript": "^5.6.2"
"typescript": "^5.6.2",
"vercel": "^41.0.1"
}
}