I am writing webapplication in Next.js, Drizzle-orm, sqlite and tested it on local machine, its working without any issues but when I move to hostinger VPS server its not working.
It gives 500 error.
import { NextResponse } from 'next/server';
import { db } from '@/lib/db/client';
import { posts } from '@/lib/db/schema';
export async function GET() {
try {
const postList = await db.select().from(posts).orderBy(posts.id);
return NextResponse.json(
{ posts: postList },
{ status: 200 }
);
} catch (error) {
console.error('Error fetching posts:', error);
return NextResponse.json({ error: 'Failed to fetch posts' }, { status: 500 });
}
}
import { useCallback, useState } from 'react';
import { toast } from 'sonner';
export default function usePosts() {
const [posts, setPosts] = useState<any[]>([]);
const fetchPosts = useCallback(async () => {
try {
const response = await fetch('/api/test');
if (!response.ok) throw new Error('Failed to fetch posts');
const data = await response.json();
setPosts(data.posts);
} catch (error) {
toast.error('Error fetching posts');
console.error(error);
}
}, []);
return { posts, fetchPosts };
}
Hostinger says its your Server, so I am lost.