Theo's Typesafe CultTTC
Theo's Typesafe Cult2y ago
2 replies
xSenny_

NextJS route.ts gets a 504 Gateway Timeout

Here is my code, I am basically fetching some data from mongodb and get this error.

Everything works fine in my local build, but not while hosted on vercel.

Here s my code
import {getEncryptedTransactions} from '@/lib/actions/restapi.actions'
import { NextRequest } from 'next/server'
export const GET = async (req: NextRequest, res: Response) => {
  try {
    const auth = req.headers.get('Authorization')

    if (auth === null) {
      return new Response(JSON.stringify({
        error: 'You did not add a Authorization header.'
      }), {status: 404, headers: {
        'Content-Type': 'application/json'
      }})
    }

    const limit = Number(req.nextUrl.searchParams.get('limit') || 10)

    const transactions = await getEncryptedTransactions(auth, limit)

    return new Response(JSON.stringify(transactions), {status: 200, headers: {
      'Content-Type': 'application/json'
    }})
  } catch (e: unknown) {
    return new Response(JSON.stringify({
      error: e instanceof Error ? e.message : 'An unknown error happened.'
    }), {status: 500, headers: {
      'Content-Type': 'application/json'
    }})
  }
}

Could it be because of it being slow?
Was this page helpful?