Skip to content

Commit

Permalink
Fix redirect function
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlgo11 committed Nov 4, 2024
1 parent d976916 commit 588db18
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions functions/redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export async function onRequestGet({ request }) {
const country = request.cf?.country?.toLowerCase();
const res = await fetch(`${api}${country}/categories.json`, {
method: 'HEAD',
cache: 'force-cache',
cf: {
cacheTtlByStatus: {
"200": 60 * 60 * 24 * 14, // Cache request 2 weeks
Expand All @@ -17,14 +16,14 @@ export async function onRequestGet({ request }) {
}
});

let uri = res.status !== 200 ? `${base}${country}/` : `${base}/int/`
let uri = res.status === 200 ? `${base}${country}/` : `${base}int/`

const params = url.searchParams.toString();
if (params) uri += `?${params}`;

return Response.redirect(uri, redirectStatus);
} catch (e) {
console.error(e);
return Response.redirect(`${base}/502/`, redirectStatus);
return Response.redirect(`${base}502/`, redirectStatus);
}
}

0 comments on commit 588db18

Please sign in to comment.