import { NextRequest } from "next/server";

import { proxyHermesRequest } from "@/lib/server/hermes-proxy";
import { assertSameOrigin } from "@/lib/server/request-guards";

async function proxyUsersRequest(request: NextRequest) {
  return proxyHermesRequest(request, `/users${request.nextUrl.search}`);
}

export async function GET(request: NextRequest) {
  return proxyUsersRequest(request);
}

export async function POST(request: NextRequest) {
  const originError = assertSameOrigin(request);

  if (originError) {
    return originError;
  }

  return proxyUsersRequest(request);
}
