Skip to content

Commit 9c5ab48

Browse files
committed
Fix API caching and sitemap redirect
1 parent 3a03343 commit 9c5ab48

4 files changed

Lines changed: 10 additions & 9 deletions

File tree

backend/src/routes/public.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ publicRoutes.post('/projects/:slug/comments', async (c) => {
264264
// Articles
265265
// ---------------------------------------------------------------------------
266266

267-
publicRoutes.get('/articles', cache60s, async (c) => {
267+
publicRoutes.get('/articles', async (c) => {
268268
const category = c.req.query('category');
269269
const limit = parseInt(c.req.query('limit') || '50', 10);
270270
let path = `articles?published=eq.true&order=published_at.desc&limit=${limit}`;
@@ -273,10 +273,11 @@ publicRoutes.get('/articles', cache60s, async (c) => {
273273
}
274274
const { data, error } = await supabase(c.env, path);
275275
if (error) return c.json({ error: error.message }, 500);
276+
c.header('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
276277
return c.json(data);
277278
});
278279

279-
publicRoutes.get('/articles/:slug', cache60s, async (c) => {
280+
publicRoutes.get('/articles/:slug', async (c) => {
280281
const slug = c.req.param('slug');
281282
const { data, error } = await supabase(
282283
c.env,
@@ -285,6 +286,7 @@ publicRoutes.get('/articles/:slug', cache60s, async (c) => {
285286
);
286287
if (error) return c.json({ error: error.message }, 500);
287288
if (!data) return c.json({ error: 'Article not found' }, 404);
289+
c.header('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
288290
return c.json(data);
289291
});
290292

frontend/public/_redirects

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
# Custom Cloudflare Pages redirect rules can be placed below
2-
/sitemap.xml https://dzd-api.demonzdevelopment.workers.dev/api/sitemap.xml 200
3-
1+
/sitemap.xml https://dzd-api.demonzdevelopment.workers.dev/api/sitemap.xml 302

frontend/src/lib/api.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,13 @@ export async function postComment(
174174
export async function fetchArticles(category?: string): Promise<Article[]> {
175175
const params = new URLSearchParams();
176176
if (category && category !== 'all') params.set('category', category);
177+
params.set('_t', Date.now().toString());
177178
const query = params.toString();
178-
return request<Article[]>(`/articles${query ? `?${query}` : ''}`);
179+
return request<Article[]>(`/articles?${query}`);
179180
}
180181

181182
export async function fetchArticle(slug: string): Promise<Article> {
182-
return request<Article>(`/articles/${encodeURIComponent(slug)}`);
183+
return request<Article>(`/articles/${encodeURIComponent(slug)}?_t=${Date.now()}`);
183184
}
184185

185186
// ─── Contact ────────────────────────────────────────────────
@@ -196,7 +197,7 @@ export async function postContact(
196197
// ─── Stats ──────────────────────────────────────────────────
197198

198199
export async function fetchStats(): Promise<Stats> {
199-
return request<Stats>('/stats');
200+
return request<Stats>(`/stats?_t=${Date.now()}`);
200201
}
201202

202203
// ─── Studio log ─────────────────────────────────────────────

frontend/src/pages/Articles.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294

295295
.cardImageContainer {
296296
position: relative;
297-
height: 180px;
297+
aspect-ratio: 16 / 10;
298298
width: 100%;
299299
background: var(--color-bg-elevated);
300300
overflow: hidden;

0 commit comments

Comments
 (0)