Next.js Discord

Discord Forum

How to send XML in NEXT 13 + with App router

Unanswered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
I want to mimic this old ExpressJS route handler in next 13

router.post("/voice", (req, res) => {
  res.set("Content-Type", "text/xml");
  res.send(twiml.toString());
});



I have gotten this far on my own, but i have no idea how to set the headers to be text/xml in NextJS

export async function POST(request: Request, response: Response) {
    return Response.json(twiml.toString());
}

This is working, but it's obviously JSON. And it cant be JSON sadly.

2 Replies

try
export async function POST(request: Request, response: Response) {
    const response = new Response(twiml.toString())
    response.headers.append('Content-Type', 'text/html')
    return response;
}
or
return new Response(twiml.toString(), { headers: { "Content-Type": "text/xml" } });