<?php
require_once '../includes/config.php';

header('Content-Type: application/json');

if (!isset($_GET['cep'])) {
    echo json_encode(['erro' => true]);
    exit;
}

$cep = preg_replace('/[^0-9]/', '', $_GET['cep']);
$url = "https://viacep.com.br/ws/{$cep}/json/";

$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response; 