-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathapp.ts
29 lines (25 loc) · 961 Bytes
/
app.ts
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
'use strict'
const QUEUEIT_CUSTOMERID = "YOUR CUSTOMERID";
const QUEUEIT_SECRETKEY = "YOUR SECRET KEY";
// Set to true, if you have any trigger(s) containing experimental 'RequestBody' condition.
const READ_REQUEST_BODY = false;
import QueueITRequestResponseHandler from "./requestResponseHandler";
declare var addEventListener: any;
declare var fetch: any;
addEventListener('fetch', (event: any) => {
event.respondWith(handleRequest(event))
})
const handleRequest = async function (event: any) {
const {request} = event;
const handler = new QueueITRequestResponseHandler(QUEUEIT_CUSTOMERID, QUEUEIT_SECRETKEY, READ_REQUEST_BODY)
let queueitResponse = await handler.onClientRequest(request);
if (queueitResponse) {
//it is a redirect- break the flow
return await handler.onClientResponse(queueitResponse);
}
else {
//call backend
const response = await fetch(request);
return await handler.onClientResponse(response);
}
}