Currently, I have been putting together a portfolio using headless WordPress and NextJs. To retrieve data from the GraphQl endpoint, I created my own functions which are working perfectly fine. However, my issue lies with media files such as images and pdfs that are stored on the WordPress CMS and brought into Next.Js as links (imported as external images) like this:
<img src="https://wordpresscms.mywebsite.com/uploads/2020/02/myimage.png" />
My goal is to have these assets hosted on the NextJs website and automatically updated during each build process. Is there a way to achieve this automatically within Next.Js? Or does this happen by default when the website is deployed to production?
The scenario I have envisioned goes as follows:
- I upload the assets to the WordPress cms.
- NextJs fetches the JSON data from WordPress containing links to external assets (using the GraphQL API at build time (getStaticProps)).
- NextJs downloads the assets.
- NextJs substitutes the external URLs with local URLs (hosted on the same host as my NextJs website).
Thank you.