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"; ...@@ -2,6 +2,7 @@ import LikeButton from "@/components/like-button";
import PostMessageForm from "@/components/post-messages"; import PostMessageForm from "@/components/post-messages";
import { prisma } from "@/lib/db"; import { prisma } from "@/lib/db";
import { Prisma } from "@prisma/client"; import { Prisma } from "@prisma/client";
/* export const revalidate = 5; */ // revalidate this page every 60 seconds
type messageType = Prisma.PostUncheckedCreateInput type messageType = Prisma.PostUncheckedCreateInput
type messageItemProps = { type messageItemProps = {
......
...@@ -3,10 +3,11 @@ import { NextRequest, NextResponse } from "next/server" ...@@ -3,10 +3,11 @@ import { NextRequest, NextResponse } from "next/server"
import { getServerSession } from "next-auth/next" import { getServerSession } from "next-auth/next"
import { authOptions } from "../auth/[...nextauth]/route"; import { authOptions } from "../auth/[...nextauth]/route";
import { Prisma } from "@prisma/client"; import { Prisma } from "@prisma/client";
import { revalidatePath, revalidateTag } from "next/cache";
type post = Prisma.PostUncheckedCreateInput type post = Prisma.PostUncheckedCreateInput
export async function POST(req: NextRequest) { export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions); const session = await getServerSession(authOptions);
if (!session) { if (!session) {
...@@ -14,11 +15,9 @@ export async function POST(req: NextRequest) { ...@@ -14,11 +15,9 @@ export async function POST(req: NextRequest) {
} }
const userId = session.user.id const userId = session.user.id
const data = await req.json() const data = await req.json()
console.log("router data: " + data.content, "status:")
console.log("router data: " + data, "status:")
try { try {
await prisma.post.create({ await prisma.post.create({
...@@ -30,6 +29,8 @@ export async function POST(req: NextRequest) { ...@@ -30,6 +29,8 @@ export async function POST(req: NextRequest) {
} }
}) })
console.log("created") console.log("created")
const path = req.nextUrl.searchParams.get('path') || '/';
revalidatePath(path);
return NextResponse.json({ status: 201, message: 'Message Created' }) return NextResponse.json({ status: 201, message: 'Message Created' })
...@@ -40,10 +41,13 @@ export async function POST(req: NextRequest) { ...@@ -40,10 +41,13 @@ export async function POST(req: NextRequest) {
} }
export async function GET(req: NextRequest, res: NextResponse) { export async function GET(req: NextRequest, res: NextResponse) {
const data = await req.json() try {
console.log("router data: " + data, "status:") const data = await req.json()
console.log("router data: " + data, "status:")
} catch (error) {
}
console.log(data)
try { try {
const messages = await prisma.post.findMany({ const messages = await prisma.post.findMany({
orderBy: { orderBy: {
......
...@@ -14,11 +14,12 @@ export default function PostMessageForm(props: { data: Post[] | null }) { ...@@ -14,11 +14,12 @@ export default function PostMessageForm(props: { data: Post[] | null }) {
async function postMessage(e: any) { async function postMessage(e: any) {
e.preventDefault() e.preventDefault()
console.log(formData) console.log(formData)
/* formData.userId = 1 */
const response = await fetch('http://localhost:3000/api/messages', { const response = await fetch('http://localhost:3000/api/messages', {
method: 'POST', method: 'POST',
body: JSON.stringify(formData) body: JSON.stringify(formData),
next: { tags: ['collection'] }
}) })
startTransition(() => { startTransition(() => {
// Refresh the current route and fetch new data from the server without // Refresh the current route and fetch new data from the server without
// losing client-side browser or React state. // 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