debug: add backend logging for hostinger api
This commit is contained in:
+54
-9
@@ -36,39 +36,84 @@ app.post('/api/config/hostinger-key', (req, res) => {
|
|||||||
res.json({ ok: true });
|
res.json({ ok: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET listar subdomínios via Hostinger API
|
// GET listar domínios via Hostinger API (Corrigido para v1/portfolio)
|
||||||
app.get('/api/subdomains', async (req, res) => {
|
app.get('/api/subdomains', async (req, res) => {
|
||||||
const cfg = loadConfig();
|
const cfg = loadConfig();
|
||||||
|
console.log('[BACKEND] Buscando domínios na Hostinger...');
|
||||||
if (!cfg.hostinger_api_key) return res.status(400).json({ error: 'API key não configurada' });
|
if (!cfg.hostinger_api_key) return res.status(400).json({ error: 'API key não configurada' });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const r = await fetch('https://developers.hostinger.com/api/dns/v1/domains', {
|
const r = await fetch('https://developers.hostinger.com/api/domains/v1/portfolio', {
|
||||||
headers: { Authorization: `Bearer ${cfg.hostinger_api_key}`, 'Content-Type': 'application/json' }
|
headers: {
|
||||||
|
'Authorization': `Bearer ${cfg.hostinger_api_key}`,
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('[BACKEND] Status Hostinger:', r.status);
|
||||||
|
|
||||||
|
if (!r.ok) {
|
||||||
|
const errText = await r.text();
|
||||||
|
console.error('[BACKEND] Erro Hostinger:', errText);
|
||||||
|
return res.status(r.status).json({ error: `Hostinger Error: ${r.status}` });
|
||||||
|
}
|
||||||
|
|
||||||
const data = await r.json();
|
const data = await r.json();
|
||||||
|
console.log('[BACKEND] Domínios encontrados:', Array.isArray(data) ? data.length : 'Não é array');
|
||||||
res.json(data);
|
res.json(data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error('[BACKEND] Crash fetch:', e.message);
|
||||||
res.status(500).json({ error: e.message });
|
res.status(500).json({ error: e.message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// POST criar subdomínio no DNS da Hostinger
|
// POST criar subdomínio no DNS da Hostinger (Corrigido para v1/zones/{domain})
|
||||||
app.post('/api/subdomains', async (req, res) => {
|
app.post('/api/subdomains', async (req, res) => {
|
||||||
const cfg = loadConfig();
|
const cfg = loadConfig();
|
||||||
if (!cfg.hostinger_api_key) return res.status(400).json({ error: 'API key não configurada' });
|
if (!cfg.hostinger_api_key) return res.status(400).json({ error: 'API key não configurada' });
|
||||||
|
|
||||||
const { domain, subdomain, type = 'A', value } = req.body;
|
const { domain, subdomain, type = 'A', value } = req.body;
|
||||||
|
console.log(`[BACKEND] Criando subdomínio ${subdomain}.${domain} -> ${value}`);
|
||||||
|
|
||||||
if (!domain || !subdomain || !value) return res.status(400).json({ error: 'domain, subdomain e value obrigatórios' });
|
if (!domain || !subdomain || !value) return res.status(400).json({ error: 'domain, subdomain e value obrigatórios' });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const r = await fetch(`https://developers.hostinger.com/api/dns/v1/domains/${domain}/records`, {
|
const r = await fetch(`https://developers.hostinger.com/api/dns/v1/zones/${domain}`, {
|
||||||
method: 'POST',
|
method: 'PUT',
|
||||||
headers: { Authorization: `Bearer ${cfg.hostinger_api_key}`, 'Content-Type': 'application/json' },
|
headers: {
|
||||||
body: JSON.stringify({ type, name: subdomain, content: value, ttl: 300 })
|
'Authorization': `Bearer ${cfg.hostinger_api_key}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
overwrite: false,
|
||||||
|
zone: [
|
||||||
|
{
|
||||||
|
name: subdomain,
|
||||||
|
type: type,
|
||||||
|
records: [
|
||||||
|
{
|
||||||
|
content: value,
|
||||||
|
ttl: 300
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('[BACKEND] Status Criação DNS:', r.status);
|
||||||
|
|
||||||
|
if (!r.ok) {
|
||||||
|
const errText = await r.text();
|
||||||
|
console.error('[BACKEND] Erro Criação DNS:', errText);
|
||||||
|
return res.status(r.status).json({ error: `Erro DNS: ${r.status}` });
|
||||||
|
}
|
||||||
|
|
||||||
const data = await r.json();
|
const data = await r.json();
|
||||||
res.json(data);
|
res.json({ ok: true, data });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error('[BACKEND] Crash Criação DNS:', e.message);
|
||||||
res.status(500).json({ error: e.message });
|
res.status(500).json({ error: e.message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user