Next.js Discord

Discord Forum

Crud operations with using server actions Next.js - 14.0.4

Unanswered
fek posted this in #help-forum
Open in Discord
fekOP
The application, which works properly in development mode, does not work in production mode. I published it with Vercel, there was no problem during the build. But it has problems while performing crud operations.

16 Replies

fekOP
example; post req

export async function createPost(formData) {
const title = formData.get("title");
const image = await imageUpload(formData.get("image"));

try {
const newPost = new Post({
title,
image,
});
await newPost.save();

revalidatePath("/")
return "Success!";
} catch (error) {
return error.message;
}
}
adds it to the database but the data does not arrive
In development mode, everything works smoothly. I add it and the instant cache is refreshed and shows me the new data, but in production mode it does not show the data from the database at all.
get request

export async function getPosts() {
try {
const posts = await Post.find();
return posts.map((post) => ({
...post._doc,
_id: post._doc._id.toString(),
}));
} catch (error) {
return error.message;
}
}
I use useState useEffect etc. while updating and I work on the client side, my data arrives late, but it arrives properly. When I try to fetch my server-side data, the data does not arrive.
I transfer the data with prop and show it in the table


import { PostTable } from "@/components/admin/tables/post/PostTable";
import { getPosts } from "@/app/actions"; // app/actions.js

export default async function AdminPostPage() {
const posts = await getPosts();
return (
<div className="my-14 max-w-[95rem] mx-auto w-full flex flex-col gap-4">
<h3 className="text-xl font-semibold">Posts</h3>
<div className="max-w-[95rem] mx-auto w-full">
<PostTable posts={posts} />
</div>
</div>
);
}
I think the data is not refreshed instantly, I think there is a problem with the cache. revalidate or server action, props vs
fekOP
I also got this error while adding a post.

405 Method Not Allowed
fekOP
An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.
@Ray hi can you help me ?
fekOP
Data showing but current data does not showing
It does not showing when new data is added or deleted.
can you show the code for the page
or can you share the repo?
@Ray or can you share the repo?
fekOP
yes