-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.js
37 lines (30 loc) · 946 Bytes
/
worker.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
async function readRequestBody(request) {
return await request.json()
}
async function readResponseBody(response) {
return await request.body
}
// Assumes an Amex notification string
function parseNotification(input) {
const chargeStatement = input.split('£')[1]
const amount = chargeStatement.split(' ')[0]
return amount;
}
async function handleRequest(request) {
const reqBody = await readRequestBody(request);
const notificationString = reqBody.notification;
const amount = parseNotification(notificationString);
console.log(amount);
await fetch("MONZO_URL", {
method: "POST",
body: JSON.stringify({"value1": amount}),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
})
return new Response(amount);
}
addEventListener("fetch", event => {
return event.respondWith(handleRequest(event.request))
})