No response is returned from route handler, while using next connect
Unanswered
Tan posted this in #help-forum
TanOP
I am new to next connect. I was trying to learn about it. I followed the docs but I dont know where I went wrong. When I send req it does work but at the end its throwing
Here is the code snippet that I am using
No response is returned from route handler error. Here is the code snippet that I am using
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { createEdgeRouter } from "next-connect";
interface RequestContext {
params: {
id: string;
};
}
const router = createEdgeRouter<NextRequest, RequestContext>();
router
// A middleware example
.use(async (req, event, next) => {
const start = Date.now();
await next(); // call next in chain
const end = Date.now();
console.log(`Request took ${end - start}ms`);
})
.get((req) => {
return NextResponse.json({ user: "here you go" });
})
.put((req) => {
return NextResponse.json({ user: "hello" });
});
export async function GET(request: NextRequest, ctx: RequestContext) {
return router.run(request, ctx);
}
export async function PUT(request: NextRequest, ctx: RequestContext) {
return router.run(request, ctx);
}