1
0
mirror of https://github.com/tormachris/cf-workers-status-page.git synced 2024-11-01 05:46:09 +01:00
cf-workers-status-page/index.js

33 lines
879 B
JavaScript
Raw Normal View History

2020-11-08 13:56:02 +01:00
import { handleEvent } from 'flareact'
import { processCronTrigger } from './src/functions/cronTrigger'
/**
* The DEBUG flag will do two things that help during development:
* 1. we will skip caching on the edge, which makes it easier to
* debug.
* 2. we will return an error message on exception in your Response rather
* than the default 404.html page.
*/
const DEBUG = false
addEventListener('fetch', (event) => {
2020-11-08 13:56:02 +01:00
try {
event.respondWith(
handleEvent(event, require.context('./pages/', true, /\.js$/), DEBUG),
)
} catch (e) {
if (DEBUG) {
return event.respondWith(
new Response(e.message || e.toString(), {
status: 500,
}),
)
}
event.respondWith(new Response('Internal Error', { status: 500 }))
}
})
addEventListener('scheduled', (event) => {
2020-11-08 13:56:02 +01:00
event.waitUntil(processCronTrigger(event))
})