const getToken = () => "admin123";
const requireApiToken = (context) => {
  const authorization = context.request.headers.get("authorization") ?? "";
  const headerToken = context.request.headers.get("x-api-key") ?? "";
  const bearerToken = authorization.startsWith("Bearer ") ? authorization.slice(7) : "";
  const token = bearerToken || headerToken;
  if (token !== getToken()) {
    return new Response(JSON.stringify({ error: "Unauthorized" }), {
      status: 401,
      headers: { "content-type": "application/json; charset=utf-8" }
    });
  }
  return null;
};

export { requireApiToken as r };
