|
|
|
# Instructions for Saving Experiment Data to Github
|
|
|
|
|
|
|
|
## Repository for Saved Data
|
|
|
|
1. Create new repository for storing data.
|
|
|
|
2. Create folder within repository for data files.
|
|
|
|
3. Write serverless function.
|
|
|
|
* Receive POST requests from verified experiments (specify 'Access-Control-Allow-Origin')
|
|
|
|
* Parse payload from the experiment
|
|
|
|
* Connect to repository via github token
|
|
|
|
* Make commit request to add experiment data as a file in the data folder
|
|
|
|
* Check success \n
|
|
|
|
> [Netlify Functions documentation](https://docs.netlify.com/functions/build-with-javascript/)<br>
|
|
|
|
> [Tutorial on writing Netlify serverless functions](https://itnext.io/how-to-build-and-deploy-serverless-functions-to-netlify-d37418f6f7be)
|
|
|
|
|
|
|
|
## Netlify Site
|
|
|
|
1. Create new Netlify site
|
|
|
|
* Link to github repository previously created
|
|
|
|
2. Change site name
|
|
|
|
3. Add github token as environment variable (Site settings -> Build & deploy -> environment).
|
|
|
|
* Token can be generated by going to Github account Settings -> Developer settings -> Personal access tokens, and creating new token with 'repo' access.<br>
|
|
|
|
> ``GITHUB TOKEN: <github personal access token>``
|
|
|
|
4. Deploy site again (rebuilt when push to repository)
|
|
|
|
|
|
|
|
## Experiment
|
|
|
|
1. At end of jsPsych experiment, organize data into struct. Struct must include an {"experiment": <name>} field for the folder within the data folder this should be saved in.
|
|
|
|
2. Create new XMLHttpRequest
|
|
|
|
* Open POST to netlify site (e.g. "https://mwoodb-savejs.netlify.app/.netlify/functions/savejs")
|
|
|
|
3. Set header information
|
|
|
|
4. Check connection
|
|
|
|
5. Send POST request
|
|
|
|
|