Next.js Discord

Discord Forum

Discord interaction endpoint with Next and Vercel

Unanswered
Northern Rough-winged Swallow posted this in #help-forum
Open in Discord
Northern Rough-winged SwallowOP
Hello, I have an api route that handles discord api interactions, it was working for months, until yesterday, it broke? it works on devlopment, but not on Vercel

function runMiddleware(req: any, res: any, fn: any) {
    return new Promise((resolve, reject) => {
        req.header = (name: string) => req.headers[name.toLowerCase()];
        console.log(req.body)
      req.body = JSON.stringify(req.body);
      fn(req, res, (result: any) => {
        if (result instanceof Error) return reject(result);
        return resolve(result);
      });
    });
}
  
export default async function command(req: NextApiRequest, res: NextApiResponse) {
    console.log(`got ${req.method} request !`)
    await runMiddleware(req, res, verifyKeyMiddleware("client key"));
    if (req.method === "POST") {
        const message = req.body as APIInteraction;
        if (message.type === InteractionType.Ping) {
            console.log("Handling Ping request");
            res.send({
                type: InteractionResponseType.PONG,
            });
        } else if (message.type === InteractionType.ApplicationCommand) {

            // do something with the command-
    }
};

5 Replies

Northern Rough-winged SwallowOP
help
Toyger
do you have any errors in logs?
@Toyger do you have any errors in logs?
Northern Rough-winged SwallowOP
no
@Toyger do you have any errors in logs?
Northern Rough-winged SwallowOP
i did a temporary fix which is to proxy the request to another server
it broke at 16:50, this friday , i guess someone at Vercel did a bad commit before the weekend