Skip to content

Commit e705cd6

Browse files
committed
feat: Implement redirects from Strapi
Fetch redirects from Strapi and configure them in Next.js.
1 parent d08ebb7 commit e705cd6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

frontend/next.config.mjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const nextConfig = {
1313
'images.pexels.com',
1414
],
1515
},
16+
redirects: () => getRedirects(),
1617
// VRAIMENT PAS OUF
1718
eslint: {
1819
ignoreDuringBuilds: true,
@@ -22,5 +23,25 @@ const nextConfig = {
2223
},
2324
};
2425

26+
export async function getRedirects() {
27+
try {
28+
const res = await fetch(`${process.env.STRAPI_API_URL}/redirects`, {
29+
headers: {
30+
Authorization: `Bearer ${process.env.STRAPI_API_TOKEN}`,
31+
},
32+
});
33+
const data = await res.json();
34+
35+
return data.map((redirect) => ({
36+
source: redirect.source,
37+
destination: redirect.destination,
38+
permanent: redirect.permanent || false,
39+
}));
40+
} catch (error) {
41+
console.error('Error fetching redirects:', error);
42+
return [];
43+
}
44+
}
45+
2546
const withNextIntl = createNextIntlPlugin();
2647
export default withNextIntl(nextConfig);

0 commit comments

Comments
 (0)