2023-02-03 15:32:07 +08:00
|
|
|
import { error } from 'itty-router-extras';
|
|
|
|
|
|
|
|
export interface Env {
|
2024-01-15 17:28:31 +08:00
|
|
|
AUTH_TOKEN: string
|
|
|
|
COPY_URL: string
|
|
|
|
R2: R2Bucket
|
2023-02-03 15:32:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const onRequest: PagesFunction<Env> = async (context : EventContext) => {
|
|
|
|
const { router } = await import('./router').then(
|
|
|
|
async (module) => (await import('./routes'), module)
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
|
|
const response: Response | undefined = await router.handle(context.request, context.env);
|
|
|
|
return response ?? error(404, 'not found');
|
|
|
|
} catch (err) {
|
|
|
|
return error(500, (err as Error).message);
|
|
|
|
}
|
|
|
|
};
|