import type { NavEnv } from './env';
import { handleApiRequest } from './api/router';

export default {
  async fetch(request: Request, env: NavEnv): Promise<Response> {
    const url = new URL(request.url);
    if (url.pathname.startsWith('/api')) {
      return handleApiRequest(request, env);
    }
    if (url.pathname === '/admin.html') {
      const dest = new URL('/admin', url.origin);
      dest.search = url.search;
      return Response.redirect(dest.toString(), 302);
    }
    return env.ASSETS.fetch(request);
  },
};
