Created
July 8, 2022 19:23
-
-
Save ardeay/bc543a7c671b5f0efe7ccd4d4422b613 to your computer and use it in GitHub Desktop.
Redirect Example for AHS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fetchRedirects, get the list of all redirects set in the content manager, loads into next.config.js | |
async function fetchZestyRedirects() { | |
// access the headless url map | |
let redirectsAPIURL = 'https://ahscom.zesty.dev/-/headless/redirects.json'; | |
try { | |
const req = await fetch(redirectsAPIURL); | |
let redirects = await req.json(); | |
let redirectsForNext = [] | |
redirects.forEach(r => { | |
redirectsForNext.push({ | |
source: r.path, | |
destination: r.target, | |
permanent: r.code == 301 ? true : false, | |
}) | |
}) | |
return redirectsForNext; | |
} catch (err){ | |
console.log(err) | |
return [] | |
} | |
} | |
module.exports = { fetchZestyRedirects }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example implementation