Publish Container / build (push) Successful in 14m53s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
import dns from 'node:dns'
|
|
import { SEAFILE_URL } from './config.js'
|
|
|
|
// Alpine's resolver (musl) fails the whole lookup when a DNS server answers the IPv6 (AAAA)
|
|
// query with "no such name" even though the IPv4 answer is fine, so Node reports ENOTFOUND for
|
|
// a host that resolves. Ask for IPv4 only, and only for the Seafile host.
|
|
export function preferIpv4ForSeafile() {
|
|
let host = ''
|
|
try {
|
|
host = SEAFILE_URL ? new URL(SEAFILE_URL).hostname : ''
|
|
} catch {
|
|
return
|
|
}
|
|
if (!host) return
|
|
|
|
const originalLookup = dns.lookup
|
|
dns.lookup = function lookup(hostname, options, callback) {
|
|
if (hostname === host) {
|
|
if (typeof options === 'function') {
|
|
callback = options
|
|
options = {}
|
|
} else if (typeof options === 'number') {
|
|
options = { family: options }
|
|
}
|
|
if (!options?.family) options = { ...options, family: 4 }
|
|
}
|
|
return originalLookup.call(this, hostname, options, callback)
|
|
}
|
|
console.log(`[seafile-dns] resolving ${host} over IPv4 only`)
|
|
}
|