#API route returning HTML not JSON

3 messages · Page 1 of 1 (latest)

quick heartBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

wooden ferry
#

idk if im wrong, but arent you missing an await here?

#src/app/admin/contacts/page.jsx
import { DataTable } from "./data-table";
import { columns } from "./columns";

async function getData() {
  const res = await fetch("http://localhost:3000/api/admin/contacts/default");
  if (!res.ok) {
    throw new Error("Failed to fetch contacts");
  }
  return res.json(); <--------------
}

export default async function Admin() {
  const data = await getData();
  console.log(data);
  return (
    <div className="m-10 bg-green-400 p-10">
      <div className="bg-orange-400">test</div>
      <div className="bg-purple-400">
        <DataTable columns={columns} data={data} />
      </div>
    </div>
  );
}
hollow hare
#

Needed to switch to client component