NGINX Deployment failing due to api route
Answered
Black-crowned Night-Heron posted this in #help-forum
Black-crowned Night-HeronOP
I am trying to deploy to nginx in order to do so I need to
here is the api route it is in the following path app/api/projects/route.ts
please let me know if there is any more information you need. The api route is to handle requests to the database (pocketbase)
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 = nextConfighere 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:
Btw you can remove the
export const revalidate = 0;Btw you can remove the
res parameter because it doesn’t exist anymore.19 Replies
@Black-crowned Night-Heron 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
js
/** @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
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)
are you trying to fetch that api route inside server components? [don't do that](https://nextjs-discord-common-questions.joulev.dev/fetching-own-api-endpoint-in-react-server-components)
same thing applies for getStaticProps
Route handlers are pre-rendered by default, you can opt out by using segment configuration:
Btw you can remove the
export const revalidate = 0;Btw you can remove the
res parameter because it doesn’t exist anymore.Answer
I am fetching in a client component
@Black-crowned Night-Heron I am fetching in a client component
show your client component code
@fuma Route handlers are pre-rendered by default, you can opt out by using segment configuration:
ts
export const revalidate = 0;
Btw you can remove the `res` parameter because it doesn’t exist anymore.
Black-crowned Night-HeronOP
Why would they be prerendered?
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 
