-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
33 lines (27 loc) · 769 Bytes
/
worker.js
File metadata and controls
33 lines (27 loc) · 769 Bytes
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
import Toucan from 'toucan-js'
import { github } from 'worker-auth-providers'
export default {
fetch: async (req, env, ctx) => {
const dsn = env.SENTRY_DSN
const sentry = new Toucan({ dsn, ctx, req })
try {
const request = req.clone()
request.id = req.headers.get
const response = await env.API.fetch(request)
if(env.LOGGING_ENABLED) {
const event = {
request: request.clone(),
response: response.clone(),
}
env.LOGS.put(request.id, { event })
}
return response
} catch (err) {
sentry.captureException(err)
return new Response('Something went wrong', {
status: 500,
statusText: 'Internal Server Error',
})
}
},
}