forked from waktaplay/discord-oidc-worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkers.ts
36 lines (32 loc) · 829 Bytes
/
workers.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
30
31
32
33
34
35
36
import {toWebHandler} from 'h3';
import type {
Request,
ScheduledEvent,
ExecutionContext,
// eslint-disable-next-line n/no-unpublished-import
} from '@cloudflare/workers-types';
import {app} from './app';
import {CloudflareEnv} from './types/cloudflare';
import {cacheRoles} from './utils/roles';
const handler = toWebHandler(app);
export default {
async fetch(request: Request, env: CloudflareEnv, ctx: ExecutionContext) {
return handler(request, {
cloudflare: {env, ctx},
});
},
async scheduled(
event: ScheduledEvent,
env: CloudflareEnv,
ctx: ExecutionContext
) {
if (
env.CACHE_ROLES &&
env.DISCORD_TOKEN &&
env.SERVERS_ROLE_CLAIMS &&
(env.SERVERS_ROLE_CLAIMS as string[]).length > 0
) {
ctx.waitUntil(cacheRoles(event, env));
}
},
};