This repository has been archived by the owner on Nov 12, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (58 loc) · 1.59 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
69
var Hapi = require('hapi');
var Tabletop = require('tabletop');
var sheetData = [],
events = [],
projects = [];
var port = eval(process.env.PORT) || 8080;
var tabletop,
KEY = '0AhSAZYKyt0p7dER5T3JOQkhjOC1nSWoxdmh5bzFkUFE';
var options = {
views: {
path: 'templates',
engines: {
html: 'handlebars'
},
partialsPath: 'partials'
}
};
function getData() {
tabletop = Tabletop.init({
key: KEY,
callback: function(data, tabletop) {
sheetData = data;
if(sheetData) {
if(sheetData.Events){
events = sheetData.Events.elements;
console.log("EVENTS", events);
} if(sheetData.Projects){
projects = sheetData.Projects.elements;
console.log("PROJECTS", projects);
}
}
},
simpleSheet: false
});
}
getData();
setInterval(getData, 60000);
// Create a server with a host, port, and options
var server = Hapi.createServer('0.0.0.0', port, options);
var routes = [
{ method: 'GET', path: '/', config: { handler: homeHandler } },
{ method: 'GET', path: '/{path*}', handler: {
directory: { path: './public', listing: true, index: true }
} }
];
server.route(routes);
function homeHandler (request, reply) {
// Render the view with the custom greeting
reply.view('index.html', {
events: events,
projects: projects
});
};
// Start the server
server.start(function () {
uri = server.info.uri;
console.log('Server started at: ' + server.info.uri);
});