Pages Edge API POST
Unanswered
Oak shoot sawfly posted this in #help-forum
Oak shoot sawflyOP
Hi, are Edge API handlers supposed to work with POST? When I fetch using POST I get an error
POST http://localhost:3000/XXX 404 (Not Found)
And with GET I don't get errors but don-t get any logs or debug.
my handler in src/pages/api/XXX.ts
and the fetch:
Thanks
POST http://localhost:3000/XXX 404 (Not Found)
And with GET I don't get errors but don-t get any logs or debug.
my handler in src/pages/api/XXX.ts
export const config = {
runtime: 'edge',
}
export default async function handler(req: NextRequest) {
console.log("execute handler");
...
return new StreamingTextResponse(stream)and the fetch:
const response = await fetch(/XXX, {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ req }),
});Thanks
9 Replies
Do you sure it’s the correct url? Normally it should starts with “apiâ€. For example: “/api/my-routeâ€
Oak shoot sawflyOP
yes and I tried both. is there a way to see the api routes that nextjs created from the files? it seems its not detecting them
Run
next build, it should output all available routes to terminal.Oak shoot sawflyOP
after the build it found the pages api but not app api route. at least its working now, run dev was not finding it
what do you mean by "pages api but not app api route"? Your code above said it's a API Route in Pages Router.
Oak shoot sawflyOP
sorry, I meant the above route started working after I did a build. which is strange. but while trying to get it to work I also created a copy on the app folder with a POST handler and it doesn’t appear on the build or dev
maybe the app one is more future proof but I don’t see any examples other than the docs so probably too new
Could you show a screenshot of your file structure?
That will help a lot