import type { Core } from '@strapi/strapi';

// SITE_ORIGENS: endereços que podem chamar a API pelo navegador (site, área do cliente). Separe por vírgula.
const origens = (process.env.SITE_ORIGENS || 'http://localhost:4321').split(',').map((s) => s.trim()).filter(Boolean);

const config: Core.Config.Middlewares = [
  'strapi::logger',
  'strapi::errors',
  'strapi::security',
  { name: 'strapi::cors', config: { origin: origens, methods: ['GET', 'POST', 'PUT', 'OPTIONS'], headers: ['Content-Type', 'Authorization', 'Accept'], keepHeaderOnError: true } },
  'strapi::poweredBy',
  'strapi::query',
  { name: 'strapi::body', config: { text: true, jsonLimit: '1mb', formLimit: '1mb', textLimit: '256kb' } },
  'strapi::session',
  'strapi::favicon',
  'strapi::public',
];

export default config;
