Status 404
Answered
`icey tea dev` posted this in #help-forum
I'm getting a status, but the route is correct.... No idea why this is happening. Tried to restart my ide but that didn't work.
const fetchEnterprises = async () => {
console.log("Fetching enterprises...");
try {
const response = await fetch("/api/enterprise", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok) {
throw new Error("Network response was not ok")
}
const data = await response.json();
setEnterprises(data.enterprises);
} catch (error) {
console.error("Failed to fetch enterprises:", error);
}
};10 Replies
export async function GET() {
const db = new DB();
const isAdmin = checkAdminRole();
if (!isAdmin) {
console.log("user is not authorized");
return new NextResponse(
JSON.stringify({ message: "User is not authorized" }),
{ status: 401 }
);
}
try {
await db.connect();
const selectQuery = "SELECT * FROM enterprises ORDER BY id";
const result = await db.query(selectQuery);
return new NextResponse(
JSON.stringify({ enterprises: result.rows }),
{ status: 200 }
);
} catch (error) {
console.log("Error retrieving enterprises: " + error)
return new NextResponse(
JSON.stringify({ message: "Error retrieving enterprises" }),
{ status: 400 }
);
} finally {
await db.disconnect();
}
}
my GET route asw
try removing the
.next folder and restarting the dev serverfuck my file name was
router.ts
not route.ts
you're a lifesaver, thank you
