Add NEXT_PUBLIC_BUILD_TIME to config and append timestamp to API requests for fresh category data retrieval

This commit is contained in:
Bram Suurd 2024-11-05 00:14:19 +01:00
parent 4ca45042cc
commit 63aa8e2aa8
3 changed files with 26 additions and 18 deletions

View File

@ -14,6 +14,10 @@ const nextConfig = {
], ],
}, },
env: {
NEXT_PUBLIC_BUILD_TIME: Date.now(),
},
output: "export", output: "export",
basePath: "/ProxmoxVE", basePath: "/ProxmoxVE",
}; };

View File

@ -47,13 +47,15 @@ function ScriptContent() {
}; };
useEffect(() => { useEffect(() => {
fetch("api/categories") fetch(
.then((response) => response.json()) `/api/categories?_=${process.env.NEXT_PUBLIC_BUILD_TIME || Date.now()}`,
.then((categories) => { )
const sortedCategories = sortCategories(categories); .then((response) => response.json())
setLinks(sortedCategories); .then((categories) => {
}) const sortedCategories = sortCategories(categories);
.catch((error) => console.error(error)); setLinks(sortedCategories);
})
.catch((error) => console.error(error));
}, []); }, []);
return ( return (

View File

@ -52,17 +52,19 @@ export default function CommandMenu() {
const fetchCategories = async () => { const fetchCategories = async () => {
setIsLoading(true); setIsLoading(true);
fetch("api/categories") fetch(
.then((response) => response.json()) `/api/categories?_=${process.env.NEXT_PUBLIC_BUILD_TIME || Date.now()}`,
.then((categories) => { )
const sortedCategories = sortCategories(categories); .then((response) => response.json())
setLinks(sortedCategories); .then((categories) => {
setIsLoading(false); const sortedCategories = sortCategories(categories);
}) setLinks(sortedCategories);
.catch((error) => { setIsLoading(false);
setIsLoading(false); })
console.error(error) .catch((error) => {
}); setIsLoading(false);
console.error(error);
});
}; };
return ( return (