Skip to content

Commit 2f4d4e5

Browse files
committed
fix cors function for alpine linux
1 parent 96c18ec commit 2f4d4e5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

js/server_functions.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const dns = require("node:dns");
22
const fs = require("node:fs");
33
const path = require("node:path");
44
const ipaddr = require("ipaddr.js");
5-
const { Agent } = require("undici");
5+
const { fetch, Agent } = require("undici");
66
const Log = require("logger");
77

88
const startUp = new Date();
@@ -98,7 +98,14 @@ async function cors (req, res) {
9898
}
9999

100100
// Pin the validated IP — fetch() reuses it instead of doing its own DNS lookup
101-
const dispatcher = new Agent({ connect: { lookup: (_h, _o, cb) => cb(null, address, family) } });
101+
const dispatcher = new Agent({
102+
connect: {
103+
lookup: (_h, _o, cb) => {
104+
const addresses = [{ address: address, family: family }];
105+
process.nextTick(() => cb(null, addresses));
106+
}
107+
}
108+
});
102109

103110
const response = await fetch(url, { dispatcher, headers: headersToSend });
104111
if (response.ok) {

0 commit comments

Comments
 (0)