mirror of
https://github.com/JonasunderscoreJones/api.jonasjones.dev.git
synced 2025-10-23 20:19:19 +02:00
15 lines
481 B
TypeScript
15 lines
481 B
TypeScript
import type { Middleware } from "./common";
|
|
|
|
// A middleware has to be a function of type Middleware
|
|
const scheduled: Middleware = async (request, env, _ctx, middlewareCtx) => {
|
|
const url = new URL(request.url);
|
|
if (url.pathname === "/__scheduled") {
|
|
const cron = url.searchParams.get("cron") ?? "";
|
|
await middlewareCtx.dispatch("scheduled", { cron });
|
|
|
|
return new Response("Ran scheduled event");
|
|
}
|
|
return middlewareCtx.next(request, env);
|
|
};
|
|
|
|
export default scheduled;
|