I have uploaded my Nextjs project to Vercel, but I have the following problem, my api route is not updating automatically. When new entries are added to the database, they are not fetched by the api.
Here is the api:
import { NextResponse } from “next/server”;
import mysql from ‘mysql2/promise’;
export async function GET() {
const connection = await mysql.createConnection({
host: 'placeholder',
user: 'placeholder',
password: 'placeholder',
database: 'placeholder',
});
try {
const query = 'SELECT * FROM orders';
const [data] = await connection.execute(query);
return NextResponse.json(data);
} catch (error) {
console.error('Fehler', error);
return NextResponse.json({
error: 'Datenbankabfrage fehlgeschlagen'
}, { status: 500 });
}
}
I have already tried it with useRouter(), but it could also be that I have used it incorrectly, otherwise I have not found anything about it so far
gerodiegarro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.