-
-
Save soc201/3a0ced9008f2c3b3a4416568033a1346 to your computer and use it in GitHub Desktop.
Airtable Netlify Lambda Function Setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lambda/airtable.js | |
const Airtable = require('airtable') | |
Airtable.configure({ | |
endpointUrl: 'https://api.airtable.com', | |
apiKey: process.env.AIRTABLE_KEY | |
}) | |
const base = Airtable.base('appNtnZ99fkL1cByn') | |
exports.handler = function(event, context, callback) { | |
const allRecords = [] | |
base('entries') | |
.select({ | |
maxRecords: 100, | |
view: 'all' | |
}) | |
.eachPage( | |
function page(records, fetchNextPage) { | |
records.forEach(function(record) { | |
allRecords.push(record) | |
}) | |
fetchNextPage() | |
}, | |
function done(err) { | |
if (err) { | |
callback(err) | |
} else { | |
const body = JSON.stringify({ records: allRecords }) | |
const response = { | |
statusCode: 200, | |
body: body, | |
headers: { | |
'content-type': 'application/json', | |
'cache-control': 'Cache-Control: max-age=300, public' | |
} | |
} | |
callback(null, response) | |
} | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment