-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
89 lines (85 loc) · 1.84 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Respond to the request
* @param {Request} request
*/
async function handleRequest(request) {
// COVID happened
const openings = [];
const message = "COVID happened, members-only until further notice."
/*
const openings = [
null, // sunday
null, // monday
null, // tuesday
[ // thursday
{
from: 17.5,
to: 22,
}
],
null, // friday
[ // saturday
{
from: 13,
to: 18,
}
]
]
*/
const formatter = new Intl.DateTimeFormat([], {
timeZone: 'Europe/Brussels',
dateStyle: 'medium',
timeStyle: 'medium'
})
formatter.format(new Date())
const now = new Date(formatter.format(new Date()))
const nowHour = now.getHours() + (now.getMinutes() / 60)
let open = false
const hours = openings[now.getDay()]
if (hours) {
for (const hour of hours) {
if (nowHour > hour.from && nowHour < hour.to) {
open = true
break
}
}
}
const response = {
api: "0.13",
space: "Liège HackerSpace",
logo: "https://lghs.be/favicon-194x194.png",
url: "https://lghs.be/",
address: "Quai de la Dérivation 54, 4020 Liège BELGIUM",
location: {
lon: 5.59001,
lat: 50.64189
},
state: {
open,
message
},
contact: {
email: "[email protected]",
twitter: "@LgHackerSpace",
issue_mail: "[email protected]",
phone: "+32 4 287 32 26"
},
issue_report_channels: [
"issue_mail"
],
projects: [
"https://wiki.liegehacker.space/",
"https://github.com/LgHS",
],
}
return new Response(JSON.stringify(response, null, 1), {
status: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
})
}