Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/api/prompt/[id]/route.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Prompt from "@models/prompt";
import User from "@models/user";

import { connectToDB } from "@utils/database";

export const GET = async (request, { params }) => {
Expand Down
27 changes: 21 additions & 6 deletions app/api/prompt/route.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import Prompt from "@models/prompt";
import User from "@models/user";

import { connectToDB } from "@utils/database";

export const GET = async (request) => {
try {
await connectToDB()

const prompts = await Prompt.find({}).populate('creator')

return new Response(JSON.stringify(prompts), { status: 200 })
await connectToDB();
const prompts = await Prompt.find().populate({
path: "creator"
});

const response = new Response(JSON.stringify(prompts), {
status: 200,
});

// Add a unique identifier to the URL to force a cache-busting reload
const url = new URL(request.url);
url.searchParams.set("t", Date.now());
response.headers.set("Cache-Control", "no-cache, no-store, must-revalidate");
response.headers.set("Pragma", "no-cache");
response.headers.set("Expires", "0");
response.headers.set("Location", url.toString());

return response;
} catch (error) {
return new Response("Failed to fetch all prompts", { status: 500 })
}
}
}
2 changes: 2 additions & 0 deletions app/api/users/[id]/posts/route.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Prompt from "@models/prompt";
import User from "@models/user";

import { connectToDB } from "@utils/database";

export const GET = async (request, { params }) => {
Expand Down