forked from portable-cto/airtable-proxy-worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js.sample
77 lines (72 loc) · 3.16 KB
/
config.js.sample
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
export const config = {
airtableApiUrl: "https://api.airtable.com",
airtableApiVersion: "v0",
airtableApiKey: "your_api_key_here",
// Time Cloudflare should cache the request to Airtable in seconds
// Note: for Cloudflare to cache the requests to Airtable the worker
// MUST be deployed on a custom domain. It will NOT work on workers.dev.
cloudflareCacheTime: 15,
// Time the browser should cache the request to Airtable in seconds
browserTTL: 60,
};
export const routes = [
{
// Name of the resource / route.
name: "Fruits",
// What path to mount the resource on
path: "/api/fruits",
// What Airtable base the api path should map to.
baseId: "your_base_id",
// What Airtable table the api path should map to.
tableId: "fruits_table_id",
// Which column should be used to select the resource in the Airtable table
// Example: if the user makes a get request to /api/fruits/:id, but we wanted
// to get the resources based on not the id column but pased on a 'slug',
// we could set the id key to find resources using the 'slug' instead.
// However, because this method is not supported by Airtable we work around this by
// doing a second request, listing all records, and use the result to find the proper
// id of the resource we're looking for. That means a second request to Airtable.
idField: "slug",
methods: {
// Only methods listed here are exposed on the API
// Available methods are list, read, create, update, delete.
list: {
// We can filter the Airtable fields that are returned in the API using either blacklist:
blacklist: ["isSecretAgent"],
// Or whitelisting (returning only the fields we want). Whitelist overrides blacklist:
whitelist: ["name", "sweetness", "isDelicious"],
// You can add a callback function to modify the responseBody directly
// For example to filter them by the value of a column, or to sort them.
// Note that this happens just before the whitelist filter operation, so make sure
// to keep the general content structure the same otherwise the filter won't work.
beforeFilter: (responseBody) => {
// Filter out all records with status "None"
responseBody.records = responseBody.records.filter((record) => {
return record.fields.status !== "None";
});
return responseBody;
},
// The afterFilter callback is called immediately before the response
// to the user. This allows you to add or remove data arbitrarily.
// If you really want to go all out, this could even allow you to encrypt
// the response, allowing for example the option to send password-protected
// back to the user.
afterFilter: async (responseBody) => {
// responseBody.records = responseBody.records.map(record => {
// if (record.passwordProtected !== undefined) {
// } else {
// return record
// }
// })
},
},
create: {
// In the case of create, update, the white and blacklist filters
// apply to both the request and the response.
// Example: attempting to create a fruit with isDelicious set will not work, only the
// name and sweetness can be set on create.
whitelist: ["name", "sweetness"],
},
},
},
];