-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (60 loc) · 1.91 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var express = require("express");
var app = express();
var Airtable = require('airtable');
var base = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base('app0TvSfnuijGrvYV');
var base1 = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base('apphmFgGo5kBKFIsD');
const bodyParser = require('body-parser');
const cors = require('cors');
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.listen(3000, () => {
console.log("Server running on port 3000");
});
app.get("/time", (req, res, next) => {
res.set('Content-Type', 'text/html')
res.set('Access-Control-Allow-Origin', '*')
base('Table 1').select({
maxRecords: 1,
view: "Grid view"
}).eachPage(function page(records, fetchNextPage) {
records.forEach(function(record) {
var currentDate = new Date()
console.log(currentDate)
var dateString = currentDate
.toString()
.split(' ')
.splice(0, 4)
.join(' ')
var nextMeeting = record.get('Formatted');
console.log(String(nextMeeting), dateString)
if (String(nextMeeting) == dateString) {
res.send("today at 3:45pm")
}
else {
res.send(String(nextMeeting))
}
});
fetchNextPage();
}, function done(err) {
if (err) { console.error(err); return; }
});
});
app.post('/post', (req, res) => {
const project = req.body;
// Output the project to the console for debugging
console.log(project);
base1('Table 1').create([
{
"fields": {"Name":project["name"],"URL":project["url"]}
}
], function(err, records) {
if (err) {
console.error(err);
return;
}
records.forEach(function (record) {
res.send(record.getId());
});
});
});