mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 18:52:56 +00:00
@@ -1,4 +1,4 @@
|
||||
import api from './api';
|
||||
import api, { API_URL } from './api';
|
||||
|
||||
export type YouTubeVideo = {
|
||||
video_id: string;
|
||||
@@ -38,12 +38,9 @@ export const getCachedYouTube = async (): Promise<YouTubeChannelPayload | null>
|
||||
// Helper: fetch static cached JSON from /cache/prefetch
|
||||
const fetchStaticYouTubeCache = async (): Promise<YouTubeChannelPayload | null> => {
|
||||
try {
|
||||
// Determine backend origin from env config similar to HomePage resolve logic
|
||||
const base = (process.env.REACT_APP_API_BASE_URL || process.env.REACT_APP_API_URL || 'http://localhost:8080/api/v1');
|
||||
const u = new URL(base);
|
||||
// Force path to backend-exposed cache file
|
||||
u.pathname = '/cache/prefetch/youtube_channel.json';
|
||||
const resp = await fetch(u.toString(), { cache: 'no-cache' });
|
||||
const origin = new URL(API_URL, typeof window !== 'undefined' ? window.location.origin : 'http://localhost:3000').origin;
|
||||
const url = `${origin}/cache/prefetch/youtube_channel.json`;
|
||||
const resp = await fetch(url, { cache: 'no-cache' });
|
||||
if (!resp.ok) return null;
|
||||
const data = (await resp.json()) as YouTubeChannelPayload;
|
||||
return sortByPublishedDate(data);
|
||||
|
||||
Reference in New Issue
Block a user