> ## Documentation Index
> Fetch the complete documentation index at: https://docs.searchcompany.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Disconnect Proxy

Returns the DNS configuration needed to restore the original DNS records and disconnect from the Search Company proxy.

Supports:

* **Apex domains** (example.com) - restores A records
* **Any subdomain** (www, shop, blog, etc.) - restores CNAME

## When to Use

Call this endpoint when a user wants to disconnect their domain from the Search Company proxy. This returns the Entri-compatible configuration to restore their domain back to its original DNS configuration.

**Important:** After Entri completes the DNS restore, call `/mark-disconnect-complete` to update the proxy status.

## What This Does

1. Looks up the original DNS records stored when the proxy was first set up
2. Returns DNS records that restore the domain to its original configuration
3. Optionally returns the SSL TXT record for cleanup (harmless to leave, but tidy to remove)
4. Does **NOT** delete CloudFront or SSL resources (they remain for fast reconnection)

## Example Request

```bash theme={null}
curl -X POST https://searchcompany-main.up.railway.app/api/domain/disconnect-proxy/org_xxx \
  -H "Authorization: Bearer YOUR_TOKEN"
```

## Example Response (WWW Subdomain)

```json theme={null}
{
  "success": true,
  "custom_domain": "www.example.com",
  "domain_type": "subdomain",
  "subdomain_label": "www",
  "original_www_cname": "cname.vercel-dns.com",
  "original_apex_a_records": null,
  "original_apex_cname": null,
  "dns_records": [
    {
      "name": "www",
      "type": "CNAME",
      "value": "cname.vercel-dns.com"
    }
  ],
  "ssl_txt_record_to_delete": {
    "name": "_acme-challenge.www",
    "type": "TXT",
    "value": "abc123xyz789_validation_token"
  }
}
```

## Example Response (Apex Domain)

```json theme={null}
{
  "success": true,
  "custom_domain": "example.com",
  "domain_type": "apex",
  "subdomain_label": "@",
  "original_www_cname": null,
  "original_apex_a_records": ["104.20.22.37", "172.66.165.95"],
  "original_apex_cname": null,
  "dns_records": [
    {
      "name": "@",
      "type": "A",
      "value": "104.20.22.37"
    },
    {
      "name": "@",
      "type": "A",
      "value": "172.66.165.95"
    }
  ],
  "ssl_txt_record_to_delete": null
}
```

## Response Fields

| Field                        | Type      | Description                               |
| ---------------------------- | --------- | ----------------------------------------- |
| success                      | boolean   | Whether the request succeeded             |
| custom\_domain               | string    | The domain being disconnected             |
| domain\_type                 | string    | apex or subdomain                         |
| subdomain\_label             | string    | www, shop, @ for apex                     |
| original\_www\_cname         | string    | Original CNAME (for subdomains)           |
| original\_apex\_a\_records   | string\[] | Original A records (for apex domains)     |
| original\_apex\_cname        | string    | Original CNAME if using flattening (rare) |
| dns\_records                 | array     | DNS records to restore via Entri          |
| ssl\_txt\_record\_to\_delete | object    | Optional TXT record to clean up           |

## Frontend Integration

Use the response to configure Entri for the disconnect flow:

```typescript theme={null}
// Get disconnect config
const response = await disconnectProxy(orgId, token);

// Launch Entri with the restore DNS records
const entriConfig = {
  applicationId: ENTRI_APP_ID,
  token: entriToken,
  prefilledDomain: response.custom_domain.replace(/^[^.]+\./, ''),
  dnsRecords: response.dns_records.map(record => ({
    type: record.type,
    host: record.name,
    value: record.value,
    ttl: 300
  }))
};

Entri.showEntri(entriConfig);

// After Entri completes successfully
const onEntriClose = async (success: boolean) => {
  if (success) {
    await markDisconnectComplete(orgId, token);
  }
};
```

## Complete Disconnect Flow

1. User clicks "Disconnect Domain"
2. Frontend calls `/disconnect-proxy` → gets restore DNS records
3. Entri restores www CNAME to original
4. Frontend calls `/mark-disconnect-complete` → sets proxy\_status = "DISCONNECTED"
5. CloudFront + ACM stay intact (for fast relink later)

## After Disconnect

After the user completes the disconnect flow:

1. Their domain points back to the original host
2. The CloudFront distribution remains but receives no traffic
3. The SSL certificate remains (auto-renews via ACM)
4. User can **reconnect instantly** by going through the 2-step DNS flow again (no CloudFront recreation needed)

## Error Responses

### Organization Not Found

```json theme={null}
{
  "detail": "Organization not found"
}
```

### No Proxy Configuration

```json theme={null}
{
  "detail": "No proxy configuration found"
}
```

### Missing Original DNS

```json theme={null}
{
  "detail": "Missing original CNAME for www. Cannot restore."
}
```
