diff --git a/.gitignore b/.gitignore index f813275..cef85eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.vscode # Logs logs *.log diff --git a/.netlify/state.json b/.netlify/state.json new file mode 100644 index 0000000..42302dc --- /dev/null +++ b/.netlify/state.json @@ -0,0 +1,3 @@ +{ + "siteId": "3030a6b8-d4bc-4888-a6c6-faa4a01b1571" +} \ No newline at end of file diff --git a/functions/todos-create.js b/functions/todos-create.js new file mode 100644 index 0000000..695d654 --- /dev/null +++ b/functions/todos-create.js @@ -0,0 +1,36 @@ +/* code from functions/todos-create.js */ +/* Import faunaDB sdk */ +const faunadb = require('faunadb') + +/* configure faunaDB Client with our secret */ +const q = faunadb.query +const client = new faunadb.Client({ + secret: process.env.FAUNADB_SERVER_SECRET +}) + +/* export our lambda function as named "handler" export */ +exports.handler = async (event, context) => { + /* parse the string body into a useable JS object */ + const data = JSON.parse(event.body) + console.log('Function `todo-create` invoked', data) + const todoItem = { + data: data + } + /* construct the fauna query */ + return client.query(q.Create(q.Ref('classes/todos'), todoItem)) + .then((response) => { + console.log('success', response) + /* Success! return the response with statusCode 200 */ + return { + statusCode: 200, + body: JSON.stringify(response) + } + }).catch((error) => { + console.log('error', error) + /* Error! return the error with statusCode 400 */ + return { + statusCode: 400, + body: JSON.stringify(error) + } + }) +} \ No newline at end of file diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 0000000..c32fa02 --- /dev/null +++ b/netlify.toml @@ -0,0 +1,6 @@ +[build] + functions = "functions" + # This will be run the site build + command = "gatsby build" + # This is the directory is publishing to netlify's CDN + publish = "public" \ No newline at end of file