Skip to content

Commit

Permalink
fix: persist record comments (#139)
Browse files Browse the repository at this point in the history
* chore: clean up ts errors

* fix: persist record comments
  • Loading branch information
willswire authored Jan 23, 2025
1 parent 8f73cdc commit 10c2772
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async function update(clientOptions: ClientOptions, newRecord: AddressableRecord
const records = (
await cloudflare.dns.records.list({
zone_id: zone.id,
name: newRecord.name,
name: newRecord.name as any,
type: newRecord.type,
})
).result;
Expand All @@ -85,19 +85,21 @@ async function update(clientOptions: ClientOptions, newRecord: AddressableRecord
throw new HttpError(400, 'No record found! You must first manually create the record.');
}

// Extract the current `proxied` status
// Extract current properties
const currentRecord = records[0] as AddressableRecord;
const proxied = currentRecord.proxied ?? false; // Default to `false` if `proxied` is undefined
const comment = currentRecord.comment;

await cloudflare.dns.records.update(records[0].id, {
content: newRecord.content,
zone_id: zone.id,
name: newRecord.name,
name: newRecord.name as any,
type: newRecord.type,
proxied, // Pass the existing "proxied" status
comment, // Pass the existing "comment"
});

console.log('DNS record for ' + newRecord.name + '(' + newRecord.type +') updated successfully to ' + newRecord.content);
console.log('DNS record for ' + newRecord.name + '(' + newRecord.type + ') updated successfully to ' + newRecord.content);

return new Response('OK', { status: 200 });
}
Expand All @@ -107,9 +109,7 @@ export default {
const url = new URL(request.url);
console.log('Requester IP: ' + request.headers.get('CF-Connecting-IP'));
console.log(request.method + ': ' + request.url);
if (request.body) {
console.log('Body: ' + await request.text());
}
console.log('Body: ' + (await request.text()));

try {
// Construct client options and DNS record
Expand Down

0 comments on commit 10c2772

Please # to comment.