Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {LitElement, html} from 'lit';
- import {customElement, property} from 'lit/decorators.js';
- import {Task} from '@lit/task';
- import type {DnsRecord} from "../types/dns"
- @customElement('dns-entry')
- class DnsEntry extends LitElement {
- @property()
- public entryid?: string;
- private _entryTask = new Task(this, {
- task: async ([entryId], {signal}) => {
- const response = await fetch(`https://dns.api.local.entitywind.io/heartbeat`, {
- method: "POST", mode: 'no-cors', headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({a: 1, b: 'Textual content', c: this.entryid}),
- signal
- });
- if (!response.ok) {
- let t = await response.json()
- throw new Error(`${t} ${response.status}`);
- }
- return await response.json() as Promise<DnsRecord>
- },
- args: () => [this.entryid]
- });
- render() {
- return this._entryTask.render({
- pending: () => html`<p>Loading dns record...</p>`,
- complete: (dnsRecord) => html`
- <ul>
- <li>${dnsRecord.domain}</li>
- <li>${dnsRecord.ttl}</li>
- <li>${dnsRecord.class}</li>
- <li>${dnsRecord.recordType}</li>
- <li>${dnsRecord.record}</li>
- </ul>
- `,
- error: (e) => html`<p>Error: ${e}</p>`
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement