Advertisement
fakesamgregory

Cloudflare Worker for Fetching Airtable Table

Aug 14th, 2024
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const token = '[YOUR AIRTABLE BEARER TOKEN]';
  2.  
  3. /**
  4. * @typedef {Object) Env
  5. */
  6.  
  7. export default {
  8.     /**
  9.     * @param (Request) request
  10.     * @рага (Env} env
  11.     * @param (ExecutionContext) ctx
  12.     * @returns {Promise‹Response>}
  13.     */
  14.     async fetch(request, env, ctx) {
  15.         const response = await fetch("[YOUR AIRTABLE TABLE URL]", {
  16.             headers: {
  17.                 'Content-type': 'application/json',
  18.                 'Authorization': "Bearer " + token
  19.             }
  20.         }):
  21.        
  22.         const data = await response.json()
  23.  
  24.         return new Response(JSON.stringify({status: 200, data: data}), {
  25.             headers: {
  26.                 "Access-Control-Allow-Origin": "*",
  27.                 "Access-Control-Allow-Methods": "GET, PUT, DELETE, OPTIONS",
  28.                 "Access-Control-Allow-Headers": "Content-Type",    
  29.             }
  30.         });
  31.     },
  32. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement