Next.js Discord

Discord Forum

Translate an express example into NextResponse

Answered
Podenco Canario posted this in #help-forum
Open in Discord
Podenco CanarioOP
Hello 👋

Sorry for the beginner question but I'm struggling translating an express response into a NextResponse
Here's the code I have in the doc :

res.set('Content-Type', 'text/plain').status(200).send(notification.challenge)

src in Twitch Documentation : https://dev.twitch.tv/docs/eventsub/handling-webhook-events/#verifying-the-event-message

The thing is I don't know if I did it right, so far I have this :
return NextResponse.json(notification.challenge, {
        headers: {
          'Content-Type': 'text/plain'
        },
        status: 200,
      })

But my guess is that it doesn't work as intended.

Also I don't have any way (I think) to get a response from Twitch to know if my response 200 was validated so I'm unsure about what's wrong
Answered by joulev
Change NextResponse.json to new NextResponse and you should be good
View full answer

10 Replies

Answer
NextResponse.json is for json, whereas here you want a raw text response
Podenco CanarioOP
new NextResponse, not NextResponse
Need the new keyword
Podenco CanarioOP
Oh mb I misread 👍
WAOW !
It works 🎉
Thanks a lot, I was scratching my head on that for an hour 😭
You’re welcome