redirect 365devnet.nl to dutch language

This commit is contained in:
becarta
2025-02-25 23:06:59 +01:00
parent 8b54955f0e
commit 1510206b1f
3 changed files with 126 additions and 12 deletions

View File

@@ -15,8 +15,13 @@ import pcep from '~/assets/images/PCEP.webp'
import MicrosoftFundamentals from '~/assets/images/microsoft-certified-fundamentals-badge.webp'
import NexthinkAppExp from '~/assets/images/CertifiedNexthinkProfessionalinApplicationExperienceManagement.webp'
import fetch from 'node-fetch';
import { getTranslation, supportedLanguages } from '~/i18n/translations';
interface IpApiResponse {
countryCode: string;
}
export async function getStaticPaths() {
return supportedLanguages.map(lang => ({
params: { lang },
@@ -28,6 +33,23 @@ if (!supportedLanguages.includes(lang)) {
return Astro.redirect('/en/');
}
// Geo-location based redirect
if (Astro.request.headers.get('host') === '365devnet.nl') {
try {
const ip = Astro.clientAddress;
const response = await fetch(`http://ip-api.com/json/${ip}`);
const data = await response.json() as IpApiResponse;
if (data?.countryCode === 'NL') {
return Astro.redirect('/nl/');
}
} catch (error) {
console.error('Geo-location error:', error);
// Fallback: Redirect to default language (English)
return Astro.redirect('/en/');
}
}
const t = getTranslation(lang);
const metadata = {