-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Next.js + Strapi - Generate Content With Faker.js
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |