-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (36 loc) · 885 Bytes
/
app.js
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
require('dotenv').config()
var Airtable = require('airtable')
Airtable.configure({
endpointUrl: 'https://api.airtable.com',
apiKey: process.env.AIRTABLE_API_KEY,
})
var base = Airtable.base('appbpIvf5JUe2PCdH')
const express = require('express')
const path = require('path')
const app = express()
app.set('view engine', 'pug')
app.set('views', path.join(__dirname, '.'))
let records
app.get('/', async (req, res) => {
if (records) {
console.log("cached")
res.render("page", {
records,
})
} else {
console.log('fetching records')
records = await base('Business Hours')
.select({
view: 'Grid view',
})
.firstPage()
res.render('page', {
records,
})
setTimeout(() => {
console.log('clearing cache')
records = null
}, 10 * 1000)
}
})
app.listen(3000, () => console.log('Server ready'))