mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +01:00
Use server-side endpoint to properly cache GH release data
This commit is contained in:
parent
0afc1b96f1
commit
d17a17bd3c
@ -3,8 +3,6 @@ import useSWR from "swr";
|
|||||||
import { compareVersions } from "compare-versions";
|
import { compareVersions } from "compare-versions";
|
||||||
import { MdNewReleases } from "react-icons/md";
|
import { MdNewReleases } from "react-icons/md";
|
||||||
|
|
||||||
import cachedFetch from "utils/proxy/cached-fetch";
|
|
||||||
|
|
||||||
export default function Version() {
|
export default function Version() {
|
||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
|
|
||||||
@ -12,9 +10,7 @@ export default function Version() {
|
|||||||
const revision = process.env.NEXT_PUBLIC_REVISION?.length ? process.env.NEXT_PUBLIC_REVISION : "dev";
|
const revision = process.env.NEXT_PUBLIC_REVISION?.length ? process.env.NEXT_PUBLIC_REVISION : "dev";
|
||||||
const version = process.env.NEXT_PUBLIC_VERSION?.length ? process.env.NEXT_PUBLIC_VERSION : "dev";
|
const version = process.env.NEXT_PUBLIC_VERSION?.length ? process.env.NEXT_PUBLIC_VERSION : "dev";
|
||||||
|
|
||||||
const cachedFetcher = (resource) => cachedFetch(resource, 5);
|
const { data: releaseData } = useSWR("/api/releases");
|
||||||
|
|
||||||
const { data: releaseData } = useSWR("https://api.github.com/repos/benphelps/homepage/releases", cachedFetcher);
|
|
||||||
|
|
||||||
// use Intl.DateTimeFormat to format the date
|
// use Intl.DateTimeFormat to format the date
|
||||||
const formatDate = (date) => {
|
const formatDate = (date) => {
|
||||||
|
6
src/pages/api/releases.js
Normal file
6
src/pages/api/releases.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import cachedFetch from "utils/proxy/cached-fetch";
|
||||||
|
|
||||||
|
export default async function handler(req, res) {
|
||||||
|
const releasesURL = "https://api.github.com/repos/benphelps/homepage/releases";
|
||||||
|
return res.send(await cachedFetch(releasesURL, 5));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user