File tree 7 files changed +102
-9
lines changed
7 files changed +102
-9
lines changed Original file line number Diff line number Diff line change 22
22
npm-debug.log *
23
23
yarn-debug.log *
24
24
yarn-error.log *
25
+
Original file line number Diff line number Diff line change
1
+ import { config } from "dotenv" ;
2
+ config ( ) ;
3
+ const key = process . env . AIRTABLE_KEY ;
4
+
5
+ const https = require ( "https" ) ;
6
+
7
+ const request = url => {
8
+ return new Promise ( ( resolve , reject ) => {
9
+ https
10
+ . get ( url , response => {
11
+ let allTheData = "" ;
12
+ response . on ( "data" , chunk => {
13
+ allTheData += chunk ;
14
+ } ) ;
15
+ response . on ( "end" , ( ) => {
16
+ try {
17
+ resolve ( JSON . parse ( allTheData ) ) ;
18
+ } catch ( e ) {
19
+ reject ( `There was an error with the JSON` ) ;
20
+ }
21
+ } ) ;
22
+ } )
23
+ . on ( "error" , err => reject ( `There was an error: ${ err } ` ) ) ;
24
+ } ) ;
25
+ } ;
26
+
27
+ export async function handler ( event , context ) {
28
+ console . log ( "test" ) ;
29
+ try {
30
+ const data = await request (
31
+ `https://api.airtable.com/v0/appkLPDVgr4TwR3lM/Imported%20table?maxRecords=3&view=Grid%20view&api_key=${ key } `
32
+ ) . then ( res => {
33
+ if ( ! res . ok ) {
34
+ const error = new Error ( "HTTP error" ) ;
35
+ error . status = res . status ;
36
+ throw error ;
37
+ }
38
+ return res . json ( ) ;
39
+ } ) ;
40
+ return {
41
+ statusCode : 200 ,
42
+ body : JSON . stringify ( data )
43
+ } ;
44
+ } catch ( error ) {
45
+ return {
46
+ statusCode : error . status || 500 ,
47
+ body : error . message
48
+ } ;
49
+ }
50
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "siteId" : " 0a4736b3-c0be-4efe-9b3f-4810feb0b204"
3
+ }
Original file line number Diff line number Diff line change
1
+ # Settings in the [build] context are global and are applied to all contexts
2
+ # unless otherwise overridden by more specific contexts.
3
+ [build ]
4
+ # Directory to change to before starting a build.
5
+ # This is where we will look for package.json/.nvmrc/etc.
6
+ base = " ./"
7
+
8
+ # Directory (relative to root of your repo) that contains the deploy-ready
9
+ # HTML files and assets generated by the build. If a base directory has
10
+ # been specified, include it in the publish directory path.
11
+ publish = " ./build"
12
+
13
+
14
+ # Directory with the serverless Lambda functions to deploy to AWS.
15
+ functions = " .netlify/functions/"
Original file line number Diff line number Diff line change 3
3
"version" : " 0.1.0" ,
4
4
"private" : true ,
5
5
"dependencies" : {
6
+ "dotenv" : " ^8.0.0" ,
6
7
"react" : " ^16.8.6" ,
7
8
"react-dom" : " ^16.8.6" ,
8
9
"react-scripts" : " 3.0.1"
Original file line number Diff line number Diff line change 1
- import React from ' react' ;
2
- import logo from ' ./logo.svg' ;
3
- import ' ./App.css' ;
1
+ import React from " react" ;
2
+ import logo from " ./logo.svg" ;
3
+ import " ./App.css" ;
4
4
5
5
function App ( ) {
6
+ const [ data , setData ] = React . useState ( null ) ;
7
+
8
+ const getData = ( ) => {
9
+ return fetch ( `/.netlify/functions/getData` )
10
+ . then ( result => {
11
+ console . log ( result . json ( ) ) ;
12
+ result . json ( ) ;
13
+ } )
14
+ . catch ( "error" ) ;
15
+ } ;
16
+
17
+ const assignData = ( ) => {
18
+ getData ( ) . then ( result => {
19
+ setData ( result . records [ 0 ] . fields . Item ) ;
20
+ } ) ;
21
+ } ;
22
+ // eslint-disable-next-line
23
+ React . useEffect ( ( ) => assignData ( ) , [ ] ) ;
6
24
return (
7
25
< div className = "App" >
8
26
< header className = "App-header" >
9
27
< img src = { logo } className = "App-logo" alt = "logo" />
10
- < p >
11
- Edit < code > src/App.js</ code > and save to reload.
12
- </ p >
28
+ < p > { data } </ p >
13
29
< a
14
30
className = "App-link"
15
31
href = "https://reactjs.org"
You can’t perform that action at this time.
0 commit comments