Skip to content
Snippets Groups Projects
Commit 01eacd87 authored by DESKTOP-9FO96TP\hehexd's avatar DESKTOP-9FO96TP\hehexd
Browse files

fixed refresh for build

parent 68454f82
No related branches found
No related tags found
1 merge request!17Fix tweeting
Pipeline #35602 passed
......@@ -2,6 +2,7 @@ import LikeButton from "@/components/like-button";
import PostMessageForm from "@/components/post-messages";
import { prisma } from "@/lib/db";
import { Prisma } from "@prisma/client";
/* export const revalidate = 5; */ // revalidate this page every 60 seconds
type messageType = Prisma.PostUncheckedCreateInput
type messageItemProps = {
......
......@@ -3,10 +3,11 @@ import { NextRequest, NextResponse } from "next/server"
import { getServerSession } from "next-auth/next"
import { authOptions } from "../auth/[...nextauth]/route";
import { Prisma } from "@prisma/client";
import { revalidatePath, revalidateTag } from "next/cache";
type post = Prisma.PostUncheckedCreateInput
export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions);
if (!session) {
......@@ -14,11 +15,9 @@ export async function POST(req: NextRequest) {
}
const userId = session.user.id
const data = await req.json()
console.log("router data: " + data, "status:")
console.log("router data: " + data.content, "status:")
try {
await prisma.post.create({
......@@ -30,6 +29,8 @@ export async function POST(req: NextRequest) {
}
})
console.log("created")
const path = req.nextUrl.searchParams.get('path') || '/';
revalidatePath(path);
return NextResponse.json({ status: 201, message: 'Message Created' })
......@@ -40,10 +41,13 @@ export async function POST(req: NextRequest) {
}
export async function GET(req: NextRequest, res: NextResponse) {
const data = await req.json()
console.log("router data: " + data, "status:")
try {
const data = await req.json()
console.log("router data: " + data, "status:")
} catch (error) {
}
console.log(data)
try {
const messages = await prisma.post.findMany({
orderBy: {
......
......@@ -14,11 +14,12 @@ export default function PostMessageForm(props: { data: Post[] | null }) {
async function postMessage(e: any) {
e.preventDefault()
console.log(formData)
/* formData.userId = 1 */
const response = await fetch('http://localhost:3000/api/messages', {
method: 'POST',
body: JSON.stringify(formData)
body: JSON.stringify(formData),
next: { tags: ['collection'] }
})
startTransition(() => {
// Refresh the current route and fetch new data from the server without
// losing client-side browser or React state.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment