init commit ⊂◉‿◉つ

This commit is contained in:
davidwells 2018-06-11 15:48:00 -07:00
commit c8c51623a6
19 changed files with 7568 additions and 0 deletions

22
.gitignore vendored Normal file
View file

@ -0,0 +1,22 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.
# dependencies
/node_modules
# testing
/coverage
# production
/build
/functions-build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

8
README.md Normal file
View file

@ -0,0 +1,8 @@
# Netlify + FaunaDB
Example of using FaunaDB with [netlify functions](https://www.netlify.com/docs/functions/)
Try it out on your own account via this link:
<!-- Markdown snippet -->
[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example)

20
functions/todos-create.js Normal file
View file

@ -0,0 +1,20 @@
'use strict';
const faunadb = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: process.env.FAUNADB_SECRET
});
module.exports = (event, callback) => {
const data = JSON.parse(event.body);
console.log("create todo", data);
return client.query(q.Create(q.Ref("classes/todos"), {data}))
.then((response) => {
console.log("success", response);
callback(false, response);
}).catch((error) => {
console.log("error", error);
callback(error)
})
};

19
functions/todos-delete.js Normal file
View file

@ -0,0 +1,19 @@
'use strict';
const faunadb = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: process.env.FAUNADB_SECRET
});
module.exports = (event, callback) => {
console.log("delete todo");
return client.query(q.Delete(q.Ref("classes/todos/"+event.pathParameters.id)))
.then((response) => {
console.log("success", response);
callback(false, response);
}).catch((error) => {
console.log("error", error);
callback(error)
})
};

View file

@ -0,0 +1,19 @@
'use strict';
const faunadb = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: process.env.FAUNADB_SECRET
});
module.exports = (event, callback) => {
console.log("readAll todo");
return client.query(q.Paginate(q.Match(q.Ref("indexes/all_todos"))))
.then((response) => {
console.log("success", response);
callback(false, response);
}).catch((error) => {
console.log("error", error);
callback(error)
})
};

View file

@ -0,0 +1,19 @@
'use strict';
const faunadb = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: process.env.FAUNADB_SECRET
});
module.exports = (event, callback) => {
console.log("readOne todo "+event.pathParameters.id);
return client.query(q.Get(q.Ref("classes/todos/"+event.pathParameters.id)))
.then((response) => {
console.log("success", response);
callback(false, response);
}).catch((error) => {
console.log("error", error);
callback(error)
})
};

20
functions/todos-update.js Normal file
View file

@ -0,0 +1,20 @@
'use strict';
const faunadb = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: process.env.FAUNADB_SECRET
});
module.exports = (event, callback) => {
const data = JSON.parse(event.body);
console.log("update todo");
return client.query(q.Update(q.Ref("classes/todos/"+event.pathParameters.id), {data}))
.then((response) => {
console.log("success", response);
callback(false, response);
}).catch((error) => {
console.log("error", error);
callback(error)
})
};

5
netlify.toml Normal file
View file

@ -0,0 +1,5 @@
[build]
Functions = "functions-build"
[template.environment]
FAUNADB_SECRET = "Your FaunaDB Server Secret"

21
package.json Normal file
View file

@ -0,0 +1,21 @@
{
"name": "netlify-fauna",
"version": "0.1.0",
"private": true,
"dependencies": {
"faunadb": "^2.0.2",
"react": "^16.4.0",
"react-dom": "^16.4.0",
"react-scripts": "1.1.4"
},
"scripts": {
"start": "react-scripts start",
"buildFunctions": "netlify-lambda build functions",
"build": "npm run buildFunctions && react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"netlify-lambda": "^0.4.0"
}
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

19
public/index.html Normal file
View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<title>Fauna + Netlify Functions</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
</body>
</html>

15
public/manifest.json Normal file
View file

@ -0,0 +1,15 @@
{
"short_name": "FaunaDB Example",
"name": "Fauna + Netlify Functions",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

28
src/App.css Normal file
View file

@ -0,0 +1,28 @@
.App {
text-align: center;
}
.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
}
.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
}
.App-title {
font-size: 1.5em;
}
.App-intro {
font-size: large;
}
@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}

21
src/App.js Normal file
View file

@ -0,0 +1,21 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Netlify + Fauna DB</h1>
</header>
<p className="App-intro">
Using FaunaDB & netlify functions
</p>
</div>
);
}
}
export default App;

9
src/App.test.js Normal file
View file

@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});

5
src/index.css Normal file
View file

@ -0,0 +1,5 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}

6
src/index.js Normal file
View file

@ -0,0 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));

9
src/logo.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.7 KiB

7303
yarn.lock Normal file

File diff suppressed because it is too large Load diff