router.ts 429 B

1234567891011121314
  1. import controllers from './controllers/index.ts';
  2. export const router = (req: Request) => {
  3. const url = new URL(req.url);
  4. for (const controller of controllers) {
  5. if (
  6. (controller.path === '*' || controller.path === url.pathname) &&
  7. (controller.method === '*' || controller.method === req.method)
  8. ) {
  9. return controller.handler(req);
  10. }
  11. }
  12. return new Response('Not Found', { status: 404 });
  13. };