POST
A function ready made for next.js in order to directly export it, which handles all incoming POST
requests that apps will trigger when users press buttons in your Frame.
It handles all the redirecting for you, correctly, based on the FrameContainer
props defined by the Frame that triggered the user action.
@param req a NextRequest
object from next/server
(Next.js app router server components)
@returns NextResponse
Usage
./app/frames/route.ts
export { POST } from "frames.js/next/server";
With url-space saving redirects
./app/frames/route.ts
import { POST as POSTNext, PreviousFrame } from "frames.js/next/server";
import { NextRequest, NextResponse } from "next/server";
export function POST(req: NextRequest, res: NextResponse) {
const redirectHandler = (prevFrame: PreviousFrame) => {
if (prevFrame.postBody?.untrustedData.buttonIndex === 4)
return "https://www.framesjs.org";
};
return POSTNext(req, res, redirectHandler);
}