I am new to both nuxt and strapi so I'm not sure what I've missed.
I am trying to create a fully static site which makes all the api calls to my localhost strapi server to fetch the data during build. Unfortunately each time I run nuxt generate and try and host the contents of the /dist file, the site makes live get requests to the api on the client side which breaks the site when not on my local machine.
In my nuxt.config.js I have my target:"static" which is all I thought I'd have to do but I am probably incorrect. I am wondering if I need to host my api in order to make this work but would really rather not do this.
I have been using fetch to get my data.
Does anyone have any ideas as to what I might be doing wrong? Very grateful for any help on the subject.
EDIT:
I wondered if there was a problem with my set up so I created a new nuxt and strapi setup with test content and found the same problem. I'm wondering now if I shouldn't be using fetch in my page components and should be using asyncData instead? The documentation definitely says fetch should be fine, so I'm trying to work out what's going on.
Further EDIT:
Not fixed, but making progress in the right direction I think. It appears that I should have been setting the routes variable in the generate variable in nuxt.config.js in order to build out my dynamic pages. However, I am still unable to view all of the images for each product... about to try using require() with the image tags in the templates.
fetch()
is totally fine to get the content because it will run both on server and client side. If you do use Nuxt's dynamic routes, it should generate it properly. As for the images, I'm not sure (didn't tried yet) but this can totally be done during the build time too.
You can generate the pages without having to go to nuxt.config.js
to my knowledge.
Last time I worked with Strapi, I tried to run the starter linked in this article and it was working flawlessly: https://strapi.io/blog/build-a-blog-using-nuxt-strapi-and-apollo
As of your build, if you plan to build it locally, you will totally be okay with hosting it afterwards. A quick yarn start
could confirm that your project is working great.
Meanwhile, you will need to be 100% sure that you are not planning on using your Strapi project again for further (client side) fetching. Should be fine by default IMO.