update env key to FAUNADB_SERVER_SECRET
This commit is contained in:
parent
9b089e7c04
commit
271721bbc0
11 changed files with 18396 additions and 111 deletions
18
README.md
18
README.md
|
|
@ -51,7 +51,7 @@ This application is using [React](https://reactjs.org/) for the frontend, [Netli
|
|||
In your terminal run the following command:
|
||||
|
||||
```bash
|
||||
export FAUNADB_SECRET=YourFaunaDBKeyHere
|
||||
export FAUNADB_SERVER_SECRET=YourFaunaDBKeyHere
|
||||
```
|
||||
|
||||
5. Run project locally
|
||||
|
|
@ -140,9 +140,9 @@ Head over to [https://app.fauna.com/sign-up](https://app.fauna.com/sign-up) to c
|
|||
|
||||
```bash
|
||||
# on mac
|
||||
export FAUNADB_SECRET=YourFaunaDBKeyHere
|
||||
export FAUNADB_SERVER_SECRET=YourFaunaDBKeyHere
|
||||
# on windows
|
||||
set FAUNADB_SECRET=YourFaunaDBKeyHere
|
||||
set FAUNADB_SERVER_SECRET=YourFaunaDBKeyHere
|
||||
```
|
||||
|
||||
Add the [/scripts/bootstrap-fauna-database.js](https://github.com/netlify/netlify-faunadb-example/blob/f965df497f0de507c2dfdb1a8a32a81bbd939314/scripts/bootstrap-fauna-database.js) to the root directory of the project. This is an idempotent script that you can run 1 million times and have the same result (one todos database)
|
||||
|
|
@ -324,7 +324,7 @@ Lets rock and roll.
|
|||
/* configure faunaDB Client with our secret */
|
||||
const q = faunadb.query
|
||||
const client = new faunadb.Client({
|
||||
secret: process.env.FAUNADB_SECRET
|
||||
secret: process.env.FAUNADB_SERVER_SECRET
|
||||
})
|
||||
|
||||
/* export our lambda function as named "handler" export */
|
||||
|
|
@ -410,7 +410,7 @@ So far we have created our `todo-create` function done and we've seen how we mak
|
|||
|
||||
const q = faunadb.query
|
||||
const client = new faunadb.Client({
|
||||
secret: process.env.FAUNADB_SECRET
|
||||
secret: process.env.FAUNADB_SERVER_SECRET
|
||||
})
|
||||
|
||||
exports.handler = (event, context, callback) => {
|
||||
|
|
@ -446,7 +446,7 @@ So far we have created our `todo-create` function done and we've seen how we mak
|
|||
|
||||
const q = faunadb.query
|
||||
const client = new faunadb.Client({
|
||||
secret: process.env.FAUNADB_SECRET
|
||||
secret: process.env.FAUNADB_SERVER_SECRET
|
||||
})
|
||||
|
||||
exports.handler = (event, context, callback) => {
|
||||
|
|
@ -491,7 +491,7 @@ So far we have created our `todo-create` function done and we've seen how we mak
|
|||
|
||||
const q = faunadb.query
|
||||
const client = new faunadb.Client({
|
||||
secret: process.env.FAUNADB_SECRET
|
||||
secret: process.env.FAUNADB_SERVER_SECRET
|
||||
})
|
||||
|
||||
exports.handler = (event, context, callback) => {
|
||||
|
|
@ -530,7 +530,7 @@ So far we have created our `todo-create` function done and we've seen how we mak
|
|||
|
||||
const q = faunadb.query
|
||||
const client = new faunadb.Client({
|
||||
secret: process.env.FAUNADB_SECRET
|
||||
secret: process.env.FAUNADB_SERVER_SECRET
|
||||
})
|
||||
|
||||
exports.handler = (event, context, callback) => {
|
||||
|
|
@ -569,7 +569,7 @@ So far we have created our `todo-create` function done and we've seen how we mak
|
|||
|
||||
const q = faunadb.query
|
||||
const client = new faunadb.Client({
|
||||
secret: process.env.FAUNADB_SECRET
|
||||
secret: process.env.FAUNADB_SERVER_SECRET
|
||||
})
|
||||
|
||||
exports.handler = (event, context, callback) => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import faunadb from 'faunadb'
|
||||
import getId from './utils/getId'
|
||||
|
||||
const q = faunadb.query
|
||||
const client = new faunadb.Client({
|
||||
|
|
@ -9,24 +8,24 @@ const client = new faunadb.Client({
|
|||
exports.handler = (event, context, callback) => {
|
||||
const data = JSON.parse(event.body)
|
||||
console.log('data', data)
|
||||
console.log("Function `todo-delete-batch` invoked", data.ids)
|
||||
console.log('Function `todo-delete-batch` invoked', data.ids)
|
||||
// construct batch query from IDs
|
||||
const deleteAllCompletedTodoQuery = data.ids.map((id) => {
|
||||
return q.Delete(q.Ref(`classes/todos/${id}`))
|
||||
})
|
||||
// Hit fauna with the query to delete the completed items
|
||||
return client.query(deleteAllCompletedTodoQuery)
|
||||
.then((response) => {
|
||||
console.log("success", response)
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(response)
|
||||
.then((response) => {
|
||||
console.log('success', response)
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(response)
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log('error', error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log("error", error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,17 +10,17 @@ exports.handler = (event, context, callback) => {
|
|||
const id = getId(event.path)
|
||||
console.log(`Function 'todo-delete' invoked. delete id: ${id}`)
|
||||
return client.query(q.Delete(q.Ref(`classes/todos/${id}`)))
|
||||
.then((response) => {
|
||||
console.log("success", response)
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(response)
|
||||
.then((response) => {
|
||||
console.log('success', response)
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(response)
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log('error', error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log("error", error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,28 +6,28 @@ const client = new faunadb.Client({
|
|||
})
|
||||
|
||||
exports.handler = (event, context, callback) => {
|
||||
console.log("Function `todo-read-all` invoked")
|
||||
return client.query(q.Paginate(q.Match(q.Ref("indexes/all_todos"))))
|
||||
.then((response) => {
|
||||
const todoRefs = response.data
|
||||
console.log("Todo refs", todoRefs)
|
||||
console.log(`${todoRefs.length} todos found`)
|
||||
// create new query out of todo refs. http://bit.ly/2LG3MLg
|
||||
const getAllTodoDataQuery = todoRefs.map((ref) => {
|
||||
return q.Get(ref)
|
||||
})
|
||||
// then query the refs
|
||||
return client.query(getAllTodoDataQuery).then((ret) => {
|
||||
console.log('Function `todo-read-all` invoked')
|
||||
return client.query(q.Paginate(q.Match(q.Ref('indexes/all_todos'))))
|
||||
.then((response) => {
|
||||
const todoRefs = response.data
|
||||
console.log('Todo refs', todoRefs)
|
||||
console.log(`${todoRefs.length} todos found`)
|
||||
// create new query out of todo refs. http://bit.ly/2LG3MLg
|
||||
const getAllTodoDataQuery = todoRefs.map((ref) => {
|
||||
return q.Get(ref)
|
||||
})
|
||||
// then query the refs
|
||||
return client.query(getAllTodoDataQuery).then((ret) => {
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(ret)
|
||||
})
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log('error', error)
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(ret)
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log("error", error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,17 +10,17 @@ exports.handler = (event, context, callback) => {
|
|||
const id = getId(event.path)
|
||||
console.log(`Function 'todo-read' invoked. Read id: ${id}`)
|
||||
return client.query(q.Get(q.Ref(`classes/todos/${id}`)))
|
||||
.then((response) => {
|
||||
console.log("success", response)
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(response)
|
||||
.then((response) => {
|
||||
console.log('success', response)
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(response)
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log('error', error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log("error", error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,17 +11,17 @@ exports.handler = (event, context, callback) => {
|
|||
const id = getId(event.path)
|
||||
console.log(`Function 'todo-update' invoked. update id: ${id}`)
|
||||
return client.query(q.Update(q.Ref(`classes/todos/${id}`), {data}))
|
||||
.then((response) => {
|
||||
console.log("success", response)
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(response)
|
||||
.then((response) => {
|
||||
console.log('success', response)
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(response)
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log('error', error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log("error", error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,4 +6,4 @@
|
|||
publish = "build"
|
||||
|
||||
[template.environment]
|
||||
FAUNADB_SECRET = "Your FaunaDB Server Secret"
|
||||
FAUNADB_SERVER_SECRET = "Your FaunaDB Server Secret"
|
||||
|
|
|
|||
18292
package-lock.json
generated
Normal file
18292
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
38
scripts/bootstrap-fauna-database.js
vendored
38
scripts/bootstrap-fauna-database.js
vendored
|
|
@ -8,11 +8,11 @@ const q = faunadb.query
|
|||
console.log(chalk.cyan('Creating your FaunaDB Database...\n'))
|
||||
|
||||
// 1. Check for required enviroment variables
|
||||
if (!process.env.FAUNADB_SECRET) {
|
||||
console.log(chalk.yellow('Required FAUNADB_SECRET enviroment variable not found.'))
|
||||
if (!process.env.FAUNADB_SERVER_SECRET) {
|
||||
console.log(chalk.yellow('Required FAUNADB_SERVER_SECRET enviroment variable not found.'))
|
||||
if (insideNetlify) {
|
||||
console.log(`Visit https://app.netlify.com/sites/YOUR_SITE_HERE/settings/deploys`)
|
||||
console.log('and set a `FAUNADB_SECRET` value in the "Build environment variables" section')
|
||||
console.log('and set a `FAUNADB_SERVER_SECRET` value in the "Build environment variables" section')
|
||||
process.exit(1)
|
||||
}
|
||||
// Local machine warning
|
||||
|
|
@ -21,20 +21,23 @@ if (!process.env.FAUNADB_SECRET) {
|
|||
console.log('You can create fauna DB keys here: https://dashboard.fauna.com/db/keys')
|
||||
console.log()
|
||||
ask(chalk.bold('Enter your faunaDB server key'), (err, answer) => {
|
||||
if (err) {
|
||||
console.log('err', err)
|
||||
}
|
||||
if (!answer) {
|
||||
console.log('Please supply a faunaDB server key')
|
||||
process.exit(1)
|
||||
}
|
||||
createFaunaDB(process.env.FAUNADB_SECRET).then(() => {
|
||||
createFaunaDB(process.env.FAUNADB_SERVER_SECRET).then(() => {
|
||||
console.log('Database created')
|
||||
})
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Has var. Do the thing
|
||||
if (process.env.FAUNADB_SECRET) {
|
||||
createFaunaDB(process.env.FAUNADB_SECRET).then(() => {
|
||||
if (process.env.FAUNADB_SERVER_SECRET) {
|
||||
createFaunaDB(process.env.FAUNADB_SERVER_SECRET).then(() => {
|
||||
console.log('Database created')
|
||||
})
|
||||
}
|
||||
|
|
@ -44,15 +47,15 @@ function createFaunaDB(key) {
|
|||
console.log('Create the database!')
|
||||
const client = new faunadb.Client({
|
||||
secret: key
|
||||
});
|
||||
})
|
||||
|
||||
/* Based on your requirements, change the schema here */
|
||||
return client.query(q.Create(q.Ref("classes"), { name: "todos" }))
|
||||
.then(()=>{
|
||||
return client.query(q.Create(q.Ref('classes'), { name: 'todos' }))
|
||||
.then(() => {
|
||||
return client.query(
|
||||
q.Create(q.Ref("indexes"), {
|
||||
name: "all_todos",
|
||||
source: q.Ref("classes/todos")
|
||||
q.Create(q.Ref('indexes'), {
|
||||
name: 'all_todos',
|
||||
source: q.Ref('classes/todos')
|
||||
}))
|
||||
}).catch((e) => {
|
||||
// Database already exists
|
||||
|
|
@ -63,7 +66,6 @@ function createFaunaDB(key) {
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
/* util methods */
|
||||
|
||||
// Test if inside netlify build context
|
||||
|
|
@ -79,9 +81,9 @@ function ask(question, callback) {
|
|||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
})
|
||||
rl.question(question + '\n', function(answer) {
|
||||
rl.close();
|
||||
callback(null, answer);
|
||||
});
|
||||
rl.close()
|
||||
callback(null, answer)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,8 @@
|
|||
const chalk = require('chalk')
|
||||
var util = require('util');
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
function clear(){
|
||||
exec('clear', function(error, stdout, stderr){
|
||||
util.puts(stdout);
|
||||
});
|
||||
}
|
||||
function checkForFaunaKey() {
|
||||
if (!process.env.FAUNADB_SECRET) {
|
||||
console.log(chalk.yellow('Required FAUNADB_SECRET enviroment variable not found.'))
|
||||
if (!process.env.FAUNADB_SERVER_SECRET) {
|
||||
console.log(chalk.yellow('Required FAUNADB_SERVER_SECRET enviroment variable not found.'))
|
||||
console.log(`
|
||||
=========================
|
||||
|
||||
|
|
@ -17,7 +10,7 @@ You can create fauna DB keys here: https://dashboard.fauna.com/db/keys
|
|||
|
||||
In your terminal run the following command:
|
||||
|
||||
export FAUNADB_SECRET=YourFaunaDBKeyHere
|
||||
export FAUNADB_SERVER_SECRET=YourFaunaDBKeyHere
|
||||
|
||||
=========================
|
||||
`)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export default class App extends Component {
|
|||
if (isLocalHost()) {
|
||||
alert('FaunaDB key is not unauthorized. Make sure you set it in terminal session where you ran `npm start`. Visit http://bit.ly/set-fauna-key for more info')
|
||||
} else {
|
||||
alert('FaunaDB key is not unauthorized. Verify the key `FAUNADB_SECRET` set in Netlify enviroment variables is correct')
|
||||
alert('FaunaDB key is not unauthorized. Verify the key `FAUNADB_SERVER_SECRET` set in Netlify enviroment variables is correct')
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
@ -206,7 +206,6 @@ export default class App extends Component {
|
|||
console.log('An API error occurred', e)
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
closeModal = (e) => {
|
||||
this.setState({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue