Skip to content

Commit

Permalink
Implement default domain and host
Browse files Browse the repository at this point in the history
Now inferred from token if possible
  • Loading branch information
anderspitman committed Sep 6, 2024
1 parent ffc9693 commit 4717b24
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
9 changes: 6 additions & 3 deletions examples/basic_browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,22 @@
value: 'v=spf1 include:spf.messagingengine.com ?all',
},
{
host: client.host ? `fake._domainkey.${client.host}` : 'fake._domainkey',
host: 'fake._domainkey.{{host}}',
type: 'CNAME',
value: 'fm1.lastlogin.io.dkim.fmhosted.com',
},
{
host: client.host ? `_acme-challenge.${client.host}`: '_acme-challenge',
host: '_acme-challenge.{{host}}',
type: 'TXT',
value: 'fake-challenge',
},
];

await client.setRecords({ records });
//await client.deleteRecords({ records });

setTimeout(() => {
client.deleteRecords({ records });
}, 5000);

</script>
</body>
Expand Down
8 changes: 3 additions & 5 deletions examples/basic_nonbrowser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import namedrop from '../../index.js';
//namedrop.setApiUri('https://anderspitman.com/namedrop');

const client = new namedrop.Client({
token: '<token-here>',
domain: 'anderspitman.com',
host: 'test',
token: '<token here>',
});

const records = await client.getRecords();
Expand All @@ -15,8 +13,8 @@ try {
await client.setRecords({
records: [
{
type: 'CNAME',
value: 'takingnames.io',
type: 'A',
value: '127.0.0.2',
},
],
});
Expand Down
12 changes: 2 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ class Client {

const recsCopy = JSON.parse(JSON.stringify(records));

for (const record of recsCopy) {
if (record.domain === undefined) {
record.domain = domain ? domain : this.domain;
}
if (record.host === undefined) {
record.host = host ? host : this.host;
}
}

const uri = `${apiUri}/${endpoint}`;
const res = await fetch(uri, {
method: 'POST',
Expand All @@ -63,7 +54,8 @@ class Client {
'Content-Type': 'text/plain'
},
body: JSON.stringify({
domain: this.domain,
domain,
host,
token: this._token,
records: recsCopy,
}),
Expand Down

0 comments on commit 4717b24

Please sign in to comment.