feat(backend): add dynamic CORS origin validator supporting newwhats.clube67.com and subdomains
continuous-integration/webhook Deploy de clube67_newwhats.local concluido com sucesso (VPS 4)

This commit is contained in:
VPS 4 Deploy Agent
2026-05-18 03:52:34 +02:00
parent 48ec69d89a
commit 5876b783b0
@@ -43,7 +43,32 @@ async function bootstrap() {
const app = express()
app.use(helmet({ crossOriginResourcePolicy: { policy: 'cross-origin' } }))
app.use(cors({ origin: env.FRONTEND_URL, credentials: true }))
const allowedOrigins = [
env.FRONTEND_URL,
'https://newwhats.clube67.com',
'https://clube67.com',
'https://www.clube67.com'
].filter(Boolean)
app.use(cors({
origin: (origin, callback) => {
// Permitir requisições sem origem (como apps mobile ou chamadas backend-to-backend)
if (!origin) return callback(null, true)
const isAllowed = allowedOrigins.some(allowed => {
return allowed === origin || origin.endsWith('.clube67.com')
}) || origin.startsWith('http://localhost')
if (isAllowed) {
callback(null, true)
} else {
logger.warn({ origin }, 'CORS bloqueado para a origem')
callback(new Error('Not allowed by CORS'))
}
},
credentials: true
}))
app.use(express.json({ limit: '10mb' }))
// Servir arquivos de mídia baixados (ambos os prefixos: acesso direto e via proxy nginx)