Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: migrate remaining API routes to App router #2571

Merged
merged 6 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions keep-ui/app/api/aws-marketplace/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { NextRequest } from "next/server";
import { redirect } from "next/navigation";

export async function POST(request: NextRequest) {
try {
// In App Router, we need to parse the request body manually
const body = await request.json();

const token = body["x-amzn-marketplace-token"];
const offerType = body["x-amzn-marketplace-offer-type"];

// Base64 encode the token
const base64EncodedToken = encodeURIComponent(btoa(token));

// In App Router, we use the redirect function for redirects
return redirect(`/signin?amt=${base64EncodedToken}`);
} catch (error) {
console.error("Error processing request:", error);
return new Response("Bad Request", { status: 400 });
}
}
24 changes: 24 additions & 0 deletions keep-ui/app/api/copilotkit/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
CopilotRuntime,
OpenAIAdapter,
copilotRuntimeNextJSAppRouterEndpoint,
} from "@copilotkit/runtime";
import OpenAI from "openai";
import { NextRequest } from "next/server";

const openai = new OpenAI({
organization: process.env.OPEN_AI_ORGANIZATION_ID,
apiKey: process.env.OPEN_AI_API_KEY,
});
const serviceAdapter = new OpenAIAdapter({ openai });
const runtime = new CopilotRuntime();

export const POST = async (req: NextRequest) => {
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
runtime,
serviceAdapter,
endpoint: "/api/copilotkit",
});

return handleRequest(req);
};
8 changes: 4 additions & 4 deletions keep-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion keep-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"moment": "^2.29.4",
"next": "^14.2.13",
"next-auth": "^5.0.0-beta.25",
"openai": "^4.72.0",
"openai": "^4.73.0",
"postcss": "^8.4.31",
"postcss-import": "^15.1.0",
"postcss-js": "^4.0.1",
Expand Down
17 changes: 0 additions & 17 deletions keep-ui/pages/_error.jsx

This file was deleted.

23 changes: 0 additions & 23 deletions keep-ui/pages/api/aws-marketplace.tsx

This file was deleted.

28 changes: 0 additions & 28 deletions keep-ui/pages/api/copilotkit.ts

This file was deleted.

Loading