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:
|
In your terminal run the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
export FAUNADB_SECRET=YourFaunaDBKeyHere
|
export FAUNADB_SERVER_SECRET=YourFaunaDBKeyHere
|
||||||
```
|
```
|
||||||
|
|
||||||
5. Run project locally
|
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
|
```bash
|
||||||
# on mac
|
# on mac
|
||||||
export FAUNADB_SECRET=YourFaunaDBKeyHere
|
export FAUNADB_SERVER_SECRET=YourFaunaDBKeyHere
|
||||||
# on windows
|
# 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)
|
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 */
|
/* configure faunaDB Client with our secret */
|
||||||
const q = faunadb.query
|
const q = faunadb.query
|
||||||
const client = new faunadb.Client({
|
const client = new faunadb.Client({
|
||||||
secret: process.env.FAUNADB_SECRET
|
secret: process.env.FAUNADB_SERVER_SECRET
|
||||||
})
|
})
|
||||||
|
|
||||||
/* export our lambda function as named "handler" export */
|
/* 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 q = faunadb.query
|
||||||
const client = new faunadb.Client({
|
const client = new faunadb.Client({
|
||||||
secret: process.env.FAUNADB_SECRET
|
secret: process.env.FAUNADB_SERVER_SECRET
|
||||||
})
|
})
|
||||||
|
|
||||||
exports.handler = (event, context, callback) => {
|
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 q = faunadb.query
|
||||||
const client = new faunadb.Client({
|
const client = new faunadb.Client({
|
||||||
secret: process.env.FAUNADB_SECRET
|
secret: process.env.FAUNADB_SERVER_SECRET
|
||||||
})
|
})
|
||||||
|
|
||||||
exports.handler = (event, context, callback) => {
|
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 q = faunadb.query
|
||||||
const client = new faunadb.Client({
|
const client = new faunadb.Client({
|
||||||
secret: process.env.FAUNADB_SECRET
|
secret: process.env.FAUNADB_SERVER_SECRET
|
||||||
})
|
})
|
||||||
|
|
||||||
exports.handler = (event, context, callback) => {
|
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 q = faunadb.query
|
||||||
const client = new faunadb.Client({
|
const client = new faunadb.Client({
|
||||||
secret: process.env.FAUNADB_SECRET
|
secret: process.env.FAUNADB_SERVER_SECRET
|
||||||
})
|
})
|
||||||
|
|
||||||
exports.handler = (event, context, callback) => {
|
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 q = faunadb.query
|
||||||
const client = new faunadb.Client({
|
const client = new faunadb.Client({
|
||||||
secret: process.env.FAUNADB_SECRET
|
secret: process.env.FAUNADB_SERVER_SECRET
|
||||||
})
|
})
|
||||||
|
|
||||||
exports.handler = (event, context, callback) => {
|
exports.handler = (event, context, callback) => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import faunadb from 'faunadb'
|
import faunadb from 'faunadb'
|
||||||
import getId from './utils/getId'
|
|
||||||
|
|
||||||
const q = faunadb.query
|
const q = faunadb.query
|
||||||
const client = new faunadb.Client({
|
const client = new faunadb.Client({
|
||||||
|
|
@ -9,7 +8,7 @@ const client = new faunadb.Client({
|
||||||
exports.handler = (event, context, callback) => {
|
exports.handler = (event, context, callback) => {
|
||||||
const data = JSON.parse(event.body)
|
const data = JSON.parse(event.body)
|
||||||
console.log('data', data)
|
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
|
// construct batch query from IDs
|
||||||
const deleteAllCompletedTodoQuery = data.ids.map((id) => {
|
const deleteAllCompletedTodoQuery = data.ids.map((id) => {
|
||||||
return q.Delete(q.Ref(`classes/todos/${id}`))
|
return q.Delete(q.Ref(`classes/todos/${id}`))
|
||||||
|
|
@ -17,13 +16,13 @@ exports.handler = (event, context, callback) => {
|
||||||
// Hit fauna with the query to delete the completed items
|
// Hit fauna with the query to delete the completed items
|
||||||
return client.query(deleteAllCompletedTodoQuery)
|
return client.query(deleteAllCompletedTodoQuery)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log("success", response)
|
console.log('success', response)
|
||||||
return callback(null, {
|
return callback(null, {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
body: JSON.stringify(response)
|
body: JSON.stringify(response)
|
||||||
})
|
})
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.log("error", error)
|
console.log('error', error)
|
||||||
return callback(null, {
|
return callback(null, {
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
body: JSON.stringify(error)
|
body: JSON.stringify(error)
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,13 @@ exports.handler = (event, context, callback) => {
|
||||||
console.log(`Function 'todo-delete' invoked. delete id: ${id}`)
|
console.log(`Function 'todo-delete' invoked. delete id: ${id}`)
|
||||||
return client.query(q.Delete(q.Ref(`classes/todos/${id}`)))
|
return client.query(q.Delete(q.Ref(`classes/todos/${id}`)))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log("success", response)
|
console.log('success', response)
|
||||||
return callback(null, {
|
return callback(null, {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
body: JSON.stringify(response)
|
body: JSON.stringify(response)
|
||||||
})
|
})
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.log("error", error)
|
console.log('error', error)
|
||||||
return callback(null, {
|
return callback(null, {
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
body: JSON.stringify(error)
|
body: JSON.stringify(error)
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@ const client = new faunadb.Client({
|
||||||
})
|
})
|
||||||
|
|
||||||
exports.handler = (event, context, callback) => {
|
exports.handler = (event, context, callback) => {
|
||||||
console.log("Function `todo-read-all` invoked")
|
console.log('Function `todo-read-all` invoked')
|
||||||
return client.query(q.Paginate(q.Match(q.Ref("indexes/all_todos"))))
|
return client.query(q.Paginate(q.Match(q.Ref('indexes/all_todos'))))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const todoRefs = response.data
|
const todoRefs = response.data
|
||||||
console.log("Todo refs", todoRefs)
|
console.log('Todo refs', todoRefs)
|
||||||
console.log(`${todoRefs.length} todos found`)
|
console.log(`${todoRefs.length} todos found`)
|
||||||
// create new query out of todo refs. http://bit.ly/2LG3MLg
|
// create new query out of todo refs. http://bit.ly/2LG3MLg
|
||||||
const getAllTodoDataQuery = todoRefs.map((ref) => {
|
const getAllTodoDataQuery = todoRefs.map((ref) => {
|
||||||
|
|
@ -24,7 +24,7 @@ exports.handler = (event, context, callback) => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.log("error", error)
|
console.log('error', error)
|
||||||
return callback(null, {
|
return callback(null, {
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
body: JSON.stringify(error)
|
body: JSON.stringify(error)
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,13 @@ exports.handler = (event, context, callback) => {
|
||||||
console.log(`Function 'todo-read' invoked. Read id: ${id}`)
|
console.log(`Function 'todo-read' invoked. Read id: ${id}`)
|
||||||
return client.query(q.Get(q.Ref(`classes/todos/${id}`)))
|
return client.query(q.Get(q.Ref(`classes/todos/${id}`)))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log("success", response)
|
console.log('success', response)
|
||||||
return callback(null, {
|
return callback(null, {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
body: JSON.stringify(response)
|
body: JSON.stringify(response)
|
||||||
})
|
})
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.log("error", error)
|
console.log('error', error)
|
||||||
return callback(null, {
|
return callback(null, {
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
body: JSON.stringify(error)
|
body: JSON.stringify(error)
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,13 @@ exports.handler = (event, context, callback) => {
|
||||||
console.log(`Function 'todo-update' invoked. update id: ${id}`)
|
console.log(`Function 'todo-update' invoked. update id: ${id}`)
|
||||||
return client.query(q.Update(q.Ref(`classes/todos/${id}`), {data}))
|
return client.query(q.Update(q.Ref(`classes/todos/${id}`), {data}))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log("success", response)
|
console.log('success', response)
|
||||||
return callback(null, {
|
return callback(null, {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
body: JSON.stringify(response)
|
body: JSON.stringify(response)
|
||||||
})
|
})
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.log("error", error)
|
console.log('error', error)
|
||||||
return callback(null, {
|
return callback(null, {
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
body: JSON.stringify(error)
|
body: JSON.stringify(error)
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,4 @@
|
||||||
publish = "build"
|
publish = "build"
|
||||||
|
|
||||||
[template.environment]
|
[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'))
|
console.log(chalk.cyan('Creating your FaunaDB Database...\n'))
|
||||||
|
|
||||||
// 1. Check for required enviroment variables
|
// 1. Check for required enviroment variables
|
||||||
if (!process.env.FAUNADB_SECRET) {
|
if (!process.env.FAUNADB_SERVER_SECRET) {
|
||||||
console.log(chalk.yellow('Required FAUNADB_SECRET enviroment variable not found.'))
|
console.log(chalk.yellow('Required FAUNADB_SERVER_SECRET enviroment variable not found.'))
|
||||||
if (insideNetlify) {
|
if (insideNetlify) {
|
||||||
console.log(`Visit https://app.netlify.com/sites/YOUR_SITE_HERE/settings/deploys`)
|
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)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
// Local machine warning
|
// 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('You can create fauna DB keys here: https://dashboard.fauna.com/db/keys')
|
||||||
console.log()
|
console.log()
|
||||||
ask(chalk.bold('Enter your faunaDB server key'), (err, answer) => {
|
ask(chalk.bold('Enter your faunaDB server key'), (err, answer) => {
|
||||||
|
if (err) {
|
||||||
|
console.log('err', err)
|
||||||
|
}
|
||||||
if (!answer) {
|
if (!answer) {
|
||||||
console.log('Please supply a faunaDB server key')
|
console.log('Please supply a faunaDB server key')
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
createFaunaDB(process.env.FAUNADB_SECRET).then(() => {
|
createFaunaDB(process.env.FAUNADB_SERVER_SECRET).then(() => {
|
||||||
console.log('Database created')
|
console.log('Database created')
|
||||||
})
|
})
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Has var. Do the thing
|
// Has var. Do the thing
|
||||||
if (process.env.FAUNADB_SECRET) {
|
if (process.env.FAUNADB_SERVER_SECRET) {
|
||||||
createFaunaDB(process.env.FAUNADB_SECRET).then(() => {
|
createFaunaDB(process.env.FAUNADB_SERVER_SECRET).then(() => {
|
||||||
console.log('Database created')
|
console.log('Database created')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -44,15 +47,15 @@ function createFaunaDB(key) {
|
||||||
console.log('Create the database!')
|
console.log('Create the database!')
|
||||||
const client = new faunadb.Client({
|
const client = new faunadb.Client({
|
||||||
secret: key
|
secret: key
|
||||||
});
|
})
|
||||||
|
|
||||||
/* Based on your requirements, change the schema here */
|
/* Based on your requirements, change the schema here */
|
||||||
return client.query(q.Create(q.Ref("classes"), { name: "todos" }))
|
return client.query(q.Create(q.Ref('classes'), { name: 'todos' }))
|
||||||
.then(()=>{
|
.then(() => {
|
||||||
return client.query(
|
return client.query(
|
||||||
q.Create(q.Ref("indexes"), {
|
q.Create(q.Ref('indexes'), {
|
||||||
name: "all_todos",
|
name: 'all_todos',
|
||||||
source: q.Ref("classes/todos")
|
source: q.Ref('classes/todos')
|
||||||
}))
|
}))
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
// Database already exists
|
// Database already exists
|
||||||
|
|
@ -63,7 +66,6 @@ function createFaunaDB(key) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* util methods */
|
/* util methods */
|
||||||
|
|
||||||
// Test if inside netlify build context
|
// Test if inside netlify build context
|
||||||
|
|
@ -79,9 +81,9 @@ function ask(question, callback) {
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout
|
output: process.stdout
|
||||||
});
|
})
|
||||||
rl.question(question + '\n', function(answer) {
|
rl.question(question + '\n', function(answer) {
|
||||||
rl.close();
|
rl.close()
|
||||||
callback(null, answer);
|
callback(null, answer)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,8 @@
|
||||||
const chalk = require('chalk')
|
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() {
|
function checkForFaunaKey() {
|
||||||
if (!process.env.FAUNADB_SECRET) {
|
if (!process.env.FAUNADB_SERVER_SECRET) {
|
||||||
console.log(chalk.yellow('Required FAUNADB_SECRET enviroment variable not found.'))
|
console.log(chalk.yellow('Required FAUNADB_SERVER_SECRET enviroment variable not found.'))
|
||||||
console.log(`
|
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:
|
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()) {
|
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')
|
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 {
|
} 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
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -206,7 +206,6 @@ export default class App extends Component {
|
||||||
console.log('An API error occurred', e)
|
console.log('An API error occurred', e)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
closeModal = (e) => {
|
closeModal = (e) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue