Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

refactored api routes

Daniel8dfd1598f36c
diff --git a/hooks/useLinks.tsx b/hooks/useLinks.tsx
index 0896c832..5de86e3f 100644
--- a/hooks/useLinks.tsx
+++ b/hooks/useLinks.tsx
@@ -33,7 +33,7 @@ export default function useLinks(
const encodedData = encodeURIComponent(JSON.stringify(requestBody));
const response = await fetch(
- `/api/routes/links?body=${encodeURIComponent(encodedData)}`
+ `/api/links?body=${encodeURIComponent(encodedData)}`
);
const data = await response.json();
diff --git a/lib/client/getPublicCollectionData.ts b/lib/client/getPublicCollectionData.ts
index 6179142a..d997eb7b 100644
--- a/lib/client/getPublicCollectionData.ts
+++ b/lib/client/getPublicCollectionData.ts
@@ -17,7 +17,7 @@ const getPublicCollectionData = async (
const encodedData = encodeURIComponent(JSON.stringify(requestBody));
const res = await fetch(
- "/api/public/routes/collections?body=" + encodeURIComponent(encodedData)
+ "/api/public/collections?body=" + encodeURIComponent(encodedData)
);
const data = await res.json();
diff --git a/lib/client/getPublicUserData.ts b/lib/client/getPublicUserData.ts
index 620cf9ec..4c65da31 100644
--- a/lib/client/getPublicUserData.ts
+++ b/lib/client/getPublicUserData.ts
@@ -8,7 +8,7 @@ export default async function getPublicUserData({
id?: number;
}) {
const response = await fetch(
- `/api/routes/users?id=${id}&${
+ `/api/users?id=${id}&${
username ? `username=${username?.toLowerCase()}` : undefined
}`
);
diff --git a/pages/api/routes/collections/index.ts b/pages/api/collections/index.ts
similarity index 100%
rename from pages/api/routes/collections/index.ts
rename to pages/api/collections/index.ts
diff --git a/pages/api/routes/links/index.ts b/pages/api/links/index.ts
similarity index 100%
rename from pages/api/routes/links/index.ts
rename to pages/api/links/index.ts
diff --git a/pages/api/public/routes/collections.ts b/pages/api/public/collections.ts
similarity index 100%
rename from pages/api/public/routes/collections.ts
rename to pages/api/public/collections.ts
diff --git a/pages/api/routes/tags/index.ts b/pages/api/tags/index.ts
similarity index 100%
rename from pages/api/routes/tags/index.ts
rename to pages/api/tags/index.ts
diff --git a/pages/api/routes/users/index.ts b/pages/api/users/index.ts
similarity index 100%
rename from pages/api/routes/users/index.ts
rename to pages/api/users/index.ts
diff --git a/store/account.ts b/store/account.ts
index 638848c2..4b7e9b6d 100644
--- a/store/account.ts
+++ b/store/account.ts
@@ -15,7 +15,7 @@ type AccountStore = {
const useAccountStore = create<AccountStore>()((set) => ({
account: {} as AccountSettings,
setAccount: async (id) => {
- const response = await fetch(`/api/routes/users?id=${id}`);
+ const response = await fetch(`/api/users?id=${id}`);
const data = await response.json();
@@ -24,7 +24,7 @@ const useAccountStore = create<AccountStore>()((set) => ({
if (response.ok) set({ account: { ...data.response, profilePic } });
},
updateAccount: async (user) => {
- const response = await fetch("/api/routes/users", {
+ const response = await fetch("/api/users", {
method: "PUT",
body: JSON.stringify(user),
headers: {
diff --git a/store/collections.ts b/store/collections.ts
index 5e05291d..0fade5f6 100644
--- a/store/collections.ts
+++ b/store/collections.ts
@@ -22,14 +22,14 @@ type CollectionStore = {
const useCollectionStore = create<CollectionStore>()((set) => ({
collections: [],
setCollections: async () => {
- const response = await fetch("/api/routes/collections");
+ const response = await fetch("/api/collections");
const data = await response.json();
if (response.ok) set({ collections: data.response });
},
addCollection: async (body) => {
- const response = await fetch("/api/routes/collections", {
+ const response = await fetch("/api/collections", {
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
@@ -47,7 +47,7 @@ const useCollectionStore = create<CollectionStore>()((set) => ({
return { ok: response.ok, data: data.response };
},
updateCollection: async (collection) => {
- const response = await fetch("/api/routes/collections", {
+ const response = await fetch("/api/collections", {
body: JSON.stringify(collection),
headers: {
"Content-Type": "application/json",
@@ -67,7 +67,7 @@ const useCollectionStore = create<CollectionStore>()((set) => ({
return { ok: response.ok, data: data.response };
},
removeCollection: async (id) => {
- const response = await fetch("/api/routes/collections", {
+ const response = await fetch("/api/collections", {
body: JSON.stringify({ id }),
headers: {
"Content-Type": "application/json",
diff --git a/store/links.ts b/store/links.ts
index 807e1ae8..ff256039 100644
--- a/store/links.ts
+++ b/store/links.ts
@@ -38,7 +38,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
}));
},
addLink: async (body) => {
- const response = await fetch("/api/routes/links", {
+ const response = await fetch("/api/links", {
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
@@ -59,7 +59,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
return { ok: response.ok, data: data.response };
},
updateLink: async (link) => {
- const response = await fetch("/api/routes/links", {
+ const response = await fetch("/api/links", {
body: JSON.stringify(link),
headers: {
"Content-Type": "application/json",
@@ -82,7 +82,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
return { ok: response.ok, data: data.response };
},
removeLink: async (link) => {
- const response = await fetch("/api/routes/links", {
+ const response = await fetch("/api/links", {
body: JSON.stringify(link),
headers: {
"Content-Type": "application/json",
diff --git a/store/tags.ts b/store/tags.ts
index 17b5c524..f833aa06 100644
--- a/store/tags.ts
+++ b/store/tags.ts
@@ -9,7 +9,7 @@ type TagStore = {
const useTagStore = create<TagStore>()((set) => ({
tags: [],
setTags: async () => {
- const response = await fetch("/api/routes/tags");
+ const response = await fetch("/api/tags");
const data = await response.json();