Skip to content

Commit

Permalink
make netlify function to establish airtable base connection
Browse files Browse the repository at this point in the history
  • Loading branch information
groupanimal committed Feb 10, 2020
1 parent 47de985 commit 5e831e7
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 32 deletions.
1 change: 1 addition & 0 deletions .netlify.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[build]
publish = "build"
functions = "functions"
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ module.exports = {
tabWidth: 2,
semi: true,
singleQuote: true,
jsxSingleQuote: true,
};
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
language: node_js
cache: node_modules
node_js:
- 12
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# safe-space
# Safe Space

A project for the MU
A project for the MU.

## Installation
## Installation and architecture

Clone this repo, navigate into the directory and run `npm i`,

In order to run the app, you'll need to have the Netlify CLI installed. You can do this globally on your machine by running `npm i -g netlify-cli`.

We then run `netlify dev` to start both the React server (on port 3000), the Functions server (on a random port), and the combined result on port 8888.

We are using the [Airtable.js](https://github.com/Airtable/airtable.js) npm package within Netlify Functions (i.e. AWS Lambdas) to conduct CRUD operations on our Airtable base without revealing any secrets.

[This article](https://medium.com/swlh/up-and-running-with-netlify-airtable-and-react-428959473cf0) explains set up, while [this is a useful resource](https://flaviocopes.com/airtable/) for understanding how to interact with the base using this package.
15 changes: 0 additions & 15 deletions functions/key-fetch/key-fetch.js

This file was deleted.

66 changes: 66 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.4.0",
"@testing-library/user-event": "^7.2.1",
"airtable": "^0.8.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.1",
Expand Down Expand Up @@ -37,6 +38,6 @@
"eslint-plugin-react": "^7.18.3"
},
"engines": {
"node": ">=12.x"
"node": ">=12"
}
}
27 changes: 19 additions & 8 deletions src/components/App/App.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import logo from '../../logo.svg';
import './App.css';

import getQuestions from '../../utils/getQuestions';

function App() {
const [questions, setQuestions] = useState(null);

useEffect(() => {
getQuestions.then(records => {
setQuestions(records);
});
}, []);

return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<div className='App'>
<header className='App-header'>
<img src={logo} className='App-logo' alt='logo' />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
className='App-link'
href='https://reactjs.org'
target='_blank'
rel='noopener noreferrer'
>
Learn React
</a>
</header>
{questions ? <h2>We have questions!</h2> : null}
</div>
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./components/App/App";
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './components/App/App';

ReactDOM.render(<App />, document.getElementById("root"));
ReactDOM.render(<App />, document.getElementById('root'));
7 changes: 7 additions & 0 deletions src/utils/getQuestions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const getQuestions = async () => {
await (
await fetch('./netlify/functions/get-questions/get-questions.js')
).json();
};

export default getQuestions;

0 comments on commit 5e831e7

Please sign in to comment.