-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
25 lines (22 loc) · 674 Bytes
/
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
//imports
import Router from "./router"
import jsonapi from "./jsonapi"
import landing from "./landing"
//request handler to respond to /links
//utilizes Router class
async function handleRequest(request) {
//create instance of router class
const r = new Router()
r.get("/links", jsonapi)
//if URL endpoint is anything but /links endpoint, display the landing page
let res = await r.route(request)
if (res.status == 404) {
//return enhanced HTML landing page
return landing()
}
//otherwise return /links end point
return res
}
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})