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

Change Response type to NextResponse type #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
11 changes: 6 additions & 5 deletions src/app/api/rpc/chain/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { getChain } from "@alchemy/aa-core";
import { NextResponse } from "next/server";

// [!region chains-route]
export async function POST(req: Request) {
const id = req.url?.split("/").pop();

const chain = getChain(parseInt(id as string));
if (!chain) {
return new Response(`Chain not found: ${chain}`, {
return new NextResponse(`Chain not found: ${chain}`, {
status: 404,
});
}
const rpcUrl = chain.rpcUrls.alchemy.http[0];

const apiKey = process.env.ALCHEMY_API_KEY;
if (!apiKey) {
return new Response("ALCHEMY_API_KEY is not set", {
return new NextResponse("ALCHEMY_API_KEY is not set", {
status: 500,
});
}
Expand All @@ -34,13 +35,13 @@ export async function POST(req: Request) {
const errorResult = await apiResponse
.json()
.catch(() => ({ message: "Failed to fetch data" }));
return Response.json(errorResult);
return NextResponse.json(errorResult);
}

const result = await apiResponse.json();
return Response.json(result);
return NextResponse.json(result);
} catch (error) {
return new Response("Server error occurred", {
return new NextResponse("Server error occurred", {
status: 500,
});
}
Expand Down