import { d as defineMiddleware, s as sequence } from './chunks/index_D0v7lZRr.mjs';
import { g as getTokenFromRequest, v as verifyToken } from './chunks/auth_C2RFIYRJ.mjs';
import 'es-module-lexer';
import './chunks/astro-designed-error-pages_BBsTzk8Q.mjs';
import 'piccolore';
import './chunks/astro/server_DePCulMI.mjs';
import 'clsx';

const isStaging = process.env.NODE_ENV === "staging" || process.env.PORT === "3002";
const onRequest$1 = defineMiddleware(async ({ request, url }, next) => {
  if (url.pathname.startsWith("/api/admin/") && !url.pathname.includes("/auth/login")) {
    const token = getTokenFromRequest(request);
    if (!token || !verifyToken(token)) {
      return new Response(JSON.stringify({ error: "Unauthorized" }), {
        status: 401,
        headers: { "Content-Type": "application/json" }
      });
    }
  }
  const response = await next();
  if (isStaging) {
    response.headers.set("X-Robots-Tag", "noindex, nofollow");
  }
  return response;
});

const onRequest = sequence(
	
	onRequest$1
	
);

export { onRequest };
