Created
May 6, 2023 06:16
-
-
Save yokoishioka/598d0bc2df0814e217062cd4128bc768 to your computer and use it in GitHub Desktop.
How to write dynamic routes to a file for pre-rendering
This file contains 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
const fs = require('fs'); | |
const axios = require('axios'); | |
const endOfLine = require('os').EOL; | |
const domain = `https://cloudengineering.studio`; | |
const routesOutputFile = 'example-file-name.txt'; | |
const routes = []; | |
getArticles(); | |
function getArticles() { | |
axios.get(articlesApi).then(res => { | |
res.data.items.forEach(item => { | |
routes.push(`/articles/${item.fields.slug}`); | |
}); | |
writeRoutes(); | |
}) | |
.catch(e => console.log(e)); | |
} | |
function writeRoutes() { | |
fs.writeFileSync(routesOutputFile, routes.join(endOfLine), 'utf8'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment