Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c8b5a82

Browse files
committedJan 21, 2025·
update codebase, async logging
1 parent 7f71305 commit c8b5a82

File tree

6 files changed

+101
-43
lines changed

6 files changed

+101
-43
lines changed
 

‎README.md

+61-22
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,81 @@
1-
# CCIP-Read-DNS-Gateway: Your Gasless DNSSEC Support
1+
# CCIP-Read-DNS-Gateway
22

3-
Welcome aboard the CCIP-Read-DNS-Gateway! This isn't just any gateway, it's a special server that provides DNS resolution services for ENS domains, with a focus on gasless DNSSEC support.
3+
## Overview
44

5-
## Inside the Gateway
5+
CCIP-Read-DNS-Gateway is a specialized server providing DNS resolution services for ENS domains with a focus on gasless DNSSEC support. It leverages the CCIP-Read protocol to offer efficient, off-chain DNS resolution and DNSSEC validation.
66

7-
Let's take a quick look at what makes this gateway tick:
7+
## Core Components
88

9-
- `index.ts`: This is the starting point for our application. It sets up the DNS prover with a specified DoH gateway URL and gets the server up and running.
9+
- `index.ts`: Express server for handling incoming requests. Mostly suitable for self-hosting or cloud development.
10+
- `worker.ts`: Cloudflare worker script for handling incoming requests in a (Cloudflare Worker) serverless environment.
1011

11-
- `app.ts`: This is where the server gets its instructions. It sets up the server with the necessary routes and handlers, and uses the `@ensdomains/dnsprovejs` library to perform DNS queries and proofs.
12+
- `app.ts`: Configures server routes and handlers. Utilizes the `@ensdomains/dnsprovejs` library for DNS queries and proof generation.
1213

13-
- `worker.ts`: This is our diligent Cloudflare worker, ready to handle incoming requests and direct them to the appropriate handlers. Useful for [getting started fast](#gateway-server).
14+
## Installation
1415

15-
## Ready to Get Started?
16+
```bash
17+
git clone https://github.com/your-repo/ccip-read-dns-gateway.git
18+
cd ccip-read-dns-gateway
19+
npm install
20+
```
1621

17-
### I will run in local
22+
## Configuration
1823

19-
To run this server locally, you'll need to provide a DoH (DNS over HTTPS) gateway URL. Set the DOH_GATEWAY_URL environment variable and you're all set! The server will use this gateway to perform DNS queries.
24+
Set the `DOH_GATEWAY_URL` environment variable to specify your DNS-over-HTTPS gateway:
2025

21-
Once you're ready, just run the index.ts file. You'll be up and running on port 8080 (default).
26+
```bash
27+
export DOH_GATEWAY_URL=https://your-doh-gateway.com/dns-query
28+
```
2229

23-
### I will run as Cloudflare Worker
30+
## Usage
2431

25-
If you want to run this as a Cloudflare Worker, the process is slightly different, but still super easy.
32+
### Local Development
2633

27-
First, you'll need to install wrangler on your machine. You can do this by following the instructions [here](https://developers.cloudflare.com/workers/wrangler/install-and-update/#install-wrangler-globally).
34+
To run the server locally:
2835

29-
Once wrangler is installed, use wrangler login to configure your account.
36+
```bash
37+
npm start
38+
```
3039

31-
Next, navigate to the wrangler.toml file and update the DOH_GATEWAY_URL environment variable with the DoH server you want to use.
40+
The server will start on `http://localhost:8080` by default.
3241

33-
Finally, run `wrangler publish` and voila! Your Cloudflare worker is up and running. Easy peasy!
42+
### Cloudflare Worker Deployment
3443

35-
## Our Companions
44+
1. Install Wrangler CLI:
45+
```bash
46+
npm install -g @cloudflare/wrangler
47+
```
3648

37-
We've got some great companions on this journey:
49+
2. Authenticate with your Cloudflare account:
50+
```bash
51+
wrangler login
52+
```
3853

39-
- [`@ensdomains/dnsprovejs`](https://github.com/ensdomains/dnsprovejs): Our reliable ally for DNS proofs.
40-
- [`@chainlink/ccip-read-server`](https://github.com/smartcontractkit/ccip-read): Sets the stage for a CCIP read server.
54+
3. Update `wrangler.toml` with your DoH gateway URL:
55+
```toml
56+
[vars]
57+
DOH_GATEWAY_URL = "https://your-doh-gateway.com/dns-query"
58+
```
4159

42-
Remember, this is just a quick overview. For a deeper understanding, feel free to explore the source code. Happy coding!
60+
4. Deploy the worker:
61+
```bash
62+
wrangler publish
63+
```
64+
65+
## API Endpoints
66+
67+
- `GET /`: Health check endpoint
68+
- `POST /`: Main endpoint for DNS resolution and proof generation
69+
70+
## Dependencies
71+
72+
- [`@ensdomains/dnsprovejs`](https://github.com/ensdomains/dnsprovejs): Library for DNS proof generation and validation
73+
- [`@chainlink/ccip-read-server`](https://github.com/smartcontractkit/ccip-read): Framework for implementing CCIP-Read servers
74+
75+
## License
76+
77+
MIT
78+
79+
## Support
80+
81+
For support, please open an issue in the GitHub repository or contact our support team at support@ens.domains.

‎ens-contracts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 0b6f79ece082234c56a532b4c6fe983ea8e9e24b

‎src/app.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ export function makeApp(
4242
}
4343

4444
if (trackEvent) {
45-
trackEvent(
46-
'resolve',
47-
{
48-
props: { name: decodedName, qtype: qTypes.toString(qtype) },
49-
},
50-
true
51-
);
45+
setTimeout(() => {
46+
trackEvent(
47+
'resolve',
48+
{
49+
props: { name: decodedName, qtype: qTypes.toString(qtype) },
50+
},
51+
true
52+
).catch(console.error);
53+
}, 0);
5254
}
5355

5456
try {
@@ -68,13 +70,15 @@ export function makeApp(
6870
return [ret];
6971
} catch (error) {
7072
if (trackEvent) {
71-
trackEvent(
72-
'error',
73-
{
74-
props: { name: decodedName, message: serializeError(error) },
75-
},
76-
true
77-
);
73+
setTimeout(() => {
74+
trackEvent(
75+
'error',
76+
{
77+
props: { name: decodedName, message: serializeError(error) },
78+
},
79+
true
80+
).catch(console.error);
81+
}, 0);
7882
}
7983

8084
return emptyRRSet;

‎src/utils.ts

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ export function serializeError(error: any) {
1212
}
1313
}
1414

15+
export const logAsync = (fn: Function, ...args: any[]) => {
16+
setTimeout(() => {
17+
Promise.resolve(fn(...args)).catch(err => {
18+
console.error('Logging error:', err);
19+
});
20+
}, 0);
21+
};
22+
1523
type DNSRecord = {
1624
rrset: string;
1725
sig: string;

‎src/worker.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { PropsDecoder, Tracker } from '@ensdomains/server-analytics';
77
import { dohQuery } from '@ensdomains/dnsprovejs';
88
import { ethers } from 'ethers';
99
import { makeApp } from './app';
10-
import { extractENSRecord } from './utils';
10+
import { extractENSRecord, logAsync } from './utils';
1111

1212
interface ENV {
1313
DOH_GATEWAY_URL: string;
@@ -60,7 +60,7 @@ const propsDecoder: PropsDecoder<CFWRequest> = (
6060
return { result: extractENSRecord(structuredData) };
6161
};
6262

63-
module.exports = {
63+
export default {
6464
fetch: async function(
6565
request: CFWRequest,
6666
env: ENV,
@@ -69,11 +69,17 @@ module.exports = {
6969
if (env.PLAUSIBLE_BASE_URL) {
7070
tracker.apiEndpoint = env.PLAUSIBLE_BASE_URL;
7171
}
72-
await tracker.trackEvent(request, 'request', {}, true);
73-
await tracker.trackPageview(request, {}, true);
74-
const router = routeHandler(env, tracker.trackEvent.bind(tracker, request));
72+
// analytics non-blocking
73+
logAsync(tracker.trackEvent, request, 'request', {}, true);
74+
logAsync(tracker.trackPageview, request, {}, true);
75+
const router = routeHandler(env, (...args: any) =>
76+
logAsync(tracker.trackEvent.bind(tracker, request), ...args)
77+
);
7578
return router
7679
.handle(request)
77-
.then(tracker.logResult.bind(this, propsDecoder, request));
80+
.then((result: any) => {
81+
logAsync(tracker.logResult, propsDecoder, request, result);
82+
return result;
83+
});
7884
},
7985
};

‎wrangler.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ccip-read-dns-worker"
22
main = "src/worker.ts"
33
compatibility_date = "2023-02-14"
4-
account_id = "de97cd2a1370a6ed2ad759f894179bff"
4+
account_id = "15dcc9085cb794bb4f29d3e8177ac880"
55
node_compat = true
66

77
[dev]

0 commit comments

Comments
 (0)
Please sign in to comment.