Next.js Discord

Discord Forum

NGINX Deployment failing due to api route

Answered
Black-crowned Night-Heron posted this in #help-forum
Open in Discord
Black-crowned Night-HeronOP
I am trying to deploy to nginx in order to do so I need to yarn build then I need to yarn start this works fine until I add an api route, then the build process fails as it tries to prerender it for some reason, here is my next config

/** @type {import('next').NextConfig} */
const nextConfig = {
  typescript: {
    ignoreBuildErrors: true,
  },
}

module.exports = nextConfig


here is the api route it is in the following path app/api/projects/route.ts
import { NextApiRequest, NextApiResponse } from 'next'
import { NextResponse } from 'next/server';
import PocketBase from 'pocketbase'


const pb = new PocketBase('http://127.0.0.1:8090');
pb.autoCancellation(false);

export async function GET(req: NextApiRequest, res: NextApiResponse) {
  const resultList = await pb.collection('portfolioPosts').getFullList({
    sort: '-created',
  });

  return NextResponse.json(resultList)
}


please let me know if there is any more information you need. The api route is to handle requests to the database (pocketbase)
Answered by fuma
Route handlers are pre-rendered by default, you can opt out by using segment configuration:
export const revalidate = 0;

Btw you can remove the res parameter because it doesn’t exist anymore.
View full answer

19 Replies

Route handlers are pre-rendered by default, you can opt out by using segment configuration:
export const revalidate = 0;

Btw you can remove the res parameter because it doesn’t exist anymore.
Answer
@Black-crowned Night-Heron I am fetching in a client component
show your client component code
when would you want them to be prerendered?
Also now the route does not work in deployment
@fuma
nginx is giving back a 404
Because GET route handlers are always pre-rendered by default in App Router. If it’s giving back 404, try run a production build locally and see if it works.
Black-crowned Night-HeronOP
yes sorry I just tried that and it does work locally
must be my nginx config
sorry
Thank you for your help!
Haha it’s fine :meow_party: