Skip to content

Commit

Permalink
Next.js + Strapi - Generate Content With Faker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandoric committed Apr 11, 2021
1 parent dfacfee commit b880658
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@emotion/styled": "^10.0.27",
"dotenv": "^8.2.0",
"emotion-theming": "^10.0.27",
"faker": "^5.5.3",
"isomorphic-unfetch": "^3.0.0",
"next": "^10.0.3",
"next-i18next": "^6.0.2",
Expand Down
40 changes: 40 additions & 0 deletions pages/generate-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Box } from 'reflexbox'
import getConfig from 'next/config'
import faker from 'faker'

const { publicRuntimeConfig } = getConfig();

function GenerateContent(){

async function addContent() {
let i

for (i = 0; i < 100; i++) {
const postData = {
Title: faker.lorem.sentence(),
Content: faker.lorem.paragraphs()
}

const generate = await fetch(`${publicRuntimeConfig.API_URL}/posts`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(postData)
})

const generateResponse = await generate.json()

console.log(generateResponse)
}
}

return (
<Box variant="container">
<button type="button" onClick={() => addContent()}>Generate Strapi Content</button>
</Box>
)
}

export default GenerateContent

0 comments on commit b880658

Please sign in to comment.