-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (35 loc) · 1.24 KB
/
server.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
const express = require("express");
const app = express();
const dotenv = require('dotenv');
dotenv.config();
var Airtable = require('airtable');
// const AirGantt = require('./airgantt.js');
let base = new Airtable({apiKey: process.env.AIRTABLE}).base('appq8nALYBhLsFKeZ');
// make all the files in 'public' availables
// https://expressjs.com/en/starter/static-files.html
app.use(express.static("public"));
// https://expressjs.com/en/starter/basic-routing.html
app.get("/", (request, response) => {
response.sendFile(__dirname + "/views/index.html");
});
// send the default array of dreams to the webpage
app.get("/tasks", (request, response) => {
let tasks = [];
base('Task').select({
view: "Main view",
// maxRecords: 3,
}).eachPage(function page(records, fetchNextPage) {
// This function (`page`) will get called for each page of records.
records.forEach(function(record) {
tasks.push({ID: record.id, ...record.fields});
});
fetchNextPage();
}, function done(err) {
response.json(tasks);
if (err) { console.error(err); return; }
});
});
// listen for requests :)
const listener = app.listen(8080, () => {
console.log("Your app is listening on port " + listener.address().port);
});