Function to write data into existing site?

I have a Vue application that I’d like to deploy to Netlify. It currently consists of two parts:

  • the Vue site itself
  • a data file (data.json) which the Vue app reads in and is used to alter the content of the site.

The Vue site code doesn’t change very often (i.e. only if I’m updating the styles or fixing bugs), so I’d like it to deploy the “usual” way when I push new code to my git repository.

The data file changes daily. I have a bunch of Typescript files and a webpack config that build down into a generate.js script. The output of that script would be the data.json file.

What I was hoping to do was to use a Netlify function to run the build script and then run the generate.js script on a daily schedule. However, I’m not sure how I can then save the output of that script (i.e. the JSON data) into my site web directory in such a way that the Vue application can access it (e.g. into mysite.com/data.json).

Any suggestions on how to handle this scenario? The only thing that seems obvious to me would be to have two applications and deploys: The Vue app would deploy to mysite.com on repo changes, and the data site would deploy to data.mysite.com (for example) on a schedule. The Vue app would just read the data from the external site. This doesn’t seem ideal, though.

Thanks!

@cviebrock Netlify’s deploys are atomic.

You can read these threads requesting similar ability to “update individual files”:

https://answers.netlify.com/t/api-update-a-single-file/52579

https://answers.netlify.com/t/is-it-possible-to-deploy-only-the-new-changed-files-via-api/87991

If you want the data to be able to be built/deployed without rebuilding/redeploying the other site files, then the way you’ve proposed using a separate site instance would work.

You could also host the data elsewhere and use a proxy.

What I ended up doing is writing one application with two functions:

  • one scheduled function, that generates the data.json object and stores it in a blob, updating every day
  • one edge function that retrieves that blob and returns it via a public endpoint

A deploy rebuilds the generate.js script (which doesn’t change often), but because it’s a scheduled function, it will continually regenerate the data file.

All of this is (or at least could be, because I haven’t finished it yet) in the same code base as the main Vue app.

Thanks for coming back and sharing your solution with the community!

Nice use of the blobs data store to solve for your use case!