Hacker News new | ask | show | jobs
by latchkey 1549 days ago
Cut out of my CF worker. Just add more routes as necessary (someone could come up with a DNS vs. HTTP specific router).

  import { Router } from 'itty-router';
  import { exportedObject } from './some/other/file';

  const router = Router();

  router.get('/update', async (request: Request, event: FetchEvent) => exportedObject.update(request, event));

  router.all('*', () => new Response('404, not found!', { status: 404 }));

  addEventListener('fetch', (event: FetchEvent) => {
 event.respondWith(router.handle(event.request, event));
  });

I don't even need to start up a http server to do testing of my handlers. I just test the functions directly.