Skip to content

Commit 3e6f7e9

Browse files
committed
refactor(dns): simplify region-specific DNS query handling and routing
1 parent 5f45446 commit 3e6f7e9

File tree

21 files changed

+21
-22
lines changed

21 files changed

+21
-22
lines changed
File renamed without changes.

api/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export const config = {
88

99
const app = new Hono().basePath('/api')
1010

11-
app.get('*', c =>
12-
c.json({ message: 'Hello Edge!', regions: REGIONS }))
11+
app.get('*', c => c.json({ message: 'Hello Edge!', regions: REGIONS }))
1312

1413
export default handle(app)

api/region/arn1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/bom1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/cdg1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/cle1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/cpt1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/dub1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/fra1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/gru1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/hkg1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/hnd1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/iad1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/icn1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/kix1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/lhr1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/pdx1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/sfo1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/sin1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

api/region/syd1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default } from '../dns-query'
1+
export { default } from '../dns'
22

33
export const config = {
44
runtime: 'edge',

lib/dns-query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ app.use('*', async (c, next) => {
3232
return corsMiddlewareHandler(c, next)
3333
})
3434

35-
app.get('*', async (c) => {
35+
app.get('/api/region/*', async (c) => {
3636
const accept = c.req.header('accept') || ''
3737
const { search } = new URL(c.req.raw.url)
3838
const { resolver = defaultResolver, dns, region } = c.req.query()
@@ -47,7 +47,7 @@ app.get('*', async (c) => {
4747
const requestByWorkerProxy = regionConfig?.provider === 'cloudflare' && !requestFromWorker
4848

4949
const dohServer = requestByWorkerProxy
50-
? ['worker', `https://${c.env.WORKER_HOST}/dns-query`]
50+
? ['worker', `https://${c.env.WORKER_HOST}/api/region/${region}`]
5151
: getResolver(resolver)
5252
const DNSapi = /application\/dns-message/.test(accept) && !requestByWorkerProxy
5353
? `${dohServer[1]}?dns=${dns}`

0 commit comments

Comments
 (0)