Skip to content

Commit 23a92d2

Browse files
fx
1 parent 0c9a78b commit 23a92d2

2 files changed

Lines changed: 17 additions & 46 deletions

File tree

src/app/api/health/[instanceId]/route.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import { NextResponse } from 'next/server'
22
import { requireAuth } from '@/lib/auth'
33
import { supabaseAdmin } from '@/lib/supabase/admin'
44
import { checkInstanceHealth } from '@/lib/openclaw/health'
5-
import { createDnsRecord, isDnsConfigured } from '@/lib/dns/cloudflare'
6-
import { logInstanceEvent } from '@/lib/control-plane'
7-
8-
const INSTANCE_DOMAIN = process.env.INSTANCE_DOMAIN ?? 'agentcomputers.app'
95

106
async function isDashboardReachable(url: string): Promise<boolean> {
117
try {
@@ -49,34 +45,13 @@ export async function GET(
4945
updates.provisioned_at = new Date().toISOString()
5046
}
5147

52-
let dashboardReachable = false
5348
if (instance.dashboard_url) {
54-
dashboardReachable = await isDashboardReachable(instance.dashboard_url)
55-
if (!dashboardReachable) {
49+
const reachable = await isDashboardReachable(instance.dashboard_url)
50+
if (!reachable) {
5651
updates.dashboard_url = null
5752
}
5853
}
5954

60-
if (!instance.dashboard_url && instance.ip_address && health.status === 'healthy' && isDnsConfigured()) {
61-
try {
62-
const dns = await createDnsRecord(instance.slug, instance.ip_address)
63-
if (dns.success) {
64-
const candidateUrl = `https://${instance.slug}.${INSTANCE_DOMAIN}`
65-
const reachable = await isDashboardReachable(candidateUrl)
66-
if (reachable) {
67-
updates.dashboard_url = candidateUrl
68-
await logInstanceEvent(instanceId, 'dns_created', {
69-
record_id: dns.id,
70-
hostname: `${instance.slug}.${INSTANCE_DOMAIN}`,
71-
source: 'health_check_retry',
72-
})
73-
}
74-
}
75-
} catch (err) {
76-
console.error('DNS retry during health check failed:', err)
77-
}
78-
}
79-
8055
await supabaseAdmin
8156
.from('instances')
8257
.update(updates)

src/lib/control-plane.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,14 @@ export async function provisionInstance(
5353
},
5454
})
5555

56-
let dnsSuccess = false
57-
if (isDnsConfigured()) {
58-
try {
59-
const dns = await createDnsRecord(instance.slug, server.public_net.ipv4.ip)
60-
dnsSuccess = dns.success
61-
if (dns.success) {
62-
await logInstanceEvent(instance.id, 'dns_created', {
63-
record_id: dns.id,
64-
hostname: `${instance.slug}.${INSTANCE_DOMAIN}`,
65-
})
66-
} else {
67-
console.error('DNS record creation returned failure for', instance.slug)
68-
}
69-
} catch (err) {
70-
console.error('DNS record creation failed:', err)
71-
}
72-
}
73-
7456
const { error: updateError } = await supabaseAdmin
7557
.from('instances')
7658
.update({
7759
hetzner_server_id: server.id,
7860
hetzner_server_type: plan.hetzner_type,
7961
ip_address: server.public_net.ipv4.ip,
8062
gateway_token: gatewayToken,
81-
dashboard_url: dnsSuccess ? dashboardUrl : null,
63+
dashboard_url: dashboardUrl,
8264
})
8365
.eq('id', instance.id)
8466

@@ -87,6 +69,20 @@ export async function provisionInstance(
8769
throw new Error(`Instance DB update failed: ${updateError.message}`)
8870
}
8971

72+
if (isDnsConfigured()) {
73+
try {
74+
const dns = await createDnsRecord(instance.slug, server.public_net.ipv4.ip)
75+
if (dns.success) {
76+
await logInstanceEvent(instance.id, 'dns_created', {
77+
record_id: dns.id,
78+
hostname: `${instance.slug}.${INSTANCE_DOMAIN}`,
79+
})
80+
}
81+
} catch (err) {
82+
console.error('DNS record creation failed:', err)
83+
}
84+
}
85+
9086
await logInstanceEvent(instance.id, 'server_created', {
9187
server_id: server.id,
9288
ip: server.public_net.ipv4.ip,

0 commit comments

Comments
 (0)