mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-12 01:50:11 +01:00
added dns checking
This commit is contained in:
parent
188a043967
commit
bab4f21056
66
server.js
66
server.js
@ -9,6 +9,7 @@ import path from 'node:path';
|
|||||||
import util from 'node:util';
|
import util from 'node:util';
|
||||||
import net from 'node:net';
|
import net from 'node:net';
|
||||||
import dns from 'node:dns';
|
import dns from 'node:dns';
|
||||||
|
import { promises as dnsPromise } from 'node:dns'
|
||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
@ -383,43 +384,36 @@ function getSessionCookieAge() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function canResolve(name, useIPv6 = true, useIPv4 = true) {
|
async function canResolve(name, useIPv6 = true, useIPv4 = true) {
|
||||||
return new Promise((resolve, reject) => {
|
try {
|
||||||
let v6Resolve
|
let v6Resolved = false;
|
||||||
let v4Resolve
|
let v4Resolved = false;
|
||||||
|
|
||||||
if (useIPv6) {
|
if (useIPv6) {
|
||||||
dns.resolve6(name, (err) => {
|
try {
|
||||||
if (err) {
|
await dnsPromise.resolve6(name);
|
||||||
v6Resolve = false
|
v6Resolved = true;
|
||||||
} else {
|
} catch (error) {
|
||||||
v6Resolve = true
|
v6Resolved = false;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
v6Resolve = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we need to check IPv4 resolution
|
||||||
if (useIPv4) {
|
if (useIPv4) {
|
||||||
dns.resolve(name, (err) => {
|
try {
|
||||||
if (err) {
|
await dnsPromise.resolve(name);
|
||||||
v4Resolve = false
|
v4Resolved = true;
|
||||||
} else {
|
} catch (error) {
|
||||||
v4Resolve = true
|
v4Resolved = false;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
v4Resolve = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v6Resolve || v4Resolve) {
|
console.log(v6Resolved, v4Resolved)
|
||||||
resolve
|
return v6Resolved || v4Resolved;
|
||||||
} else {
|
|
||||||
reject
|
} catch (error) {
|
||||||
}
|
return false;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getHasIP() {
|
async function getHasIP() {
|
||||||
@ -774,12 +768,14 @@ const preSetupTasks = async function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the hostname to use for autorun in the browser.
|
* Gets the hostname to use for autorun in the browser.
|
||||||
* @returns {string} The hostname to use for autorun
|
* @returns promise({string} The hostname to use for autorun
|
||||||
*/
|
*/
|
||||||
function getAutorunHostname(useIPv6, useIPv4) {
|
async function getAutorunHostname(useIPv6, useIPv4) {
|
||||||
if (autorunHostname === 'auto') {
|
if (autorunHostname === 'auto') {
|
||||||
|
let localhostResolve = await canResolve('localhost', useIPv6, useIPv4)
|
||||||
|
|
||||||
if (useIPv6 && useIPv4) {
|
if (useIPv6 && useIPv4) {
|
||||||
if (avoidLocalhost) return '[::1]';
|
if (avoidLocalhost || !localhostResolve) return '[::1]';
|
||||||
return 'localhost';
|
return 'localhost';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -792,6 +788,7 @@ function getAutorunHostname(useIPv6, useIPv4) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return autorunHostname;
|
return autorunHostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -803,7 +800,7 @@ function getAutorunHostname(useIPv6, useIPv4) {
|
|||||||
const postSetupTasks = async function (v6Failed, v4Failed, useIPv6, useIPv4) {
|
const postSetupTasks = async function (v6Failed, v4Failed, useIPv6, useIPv4) {
|
||||||
const autorunUrl = new URL(
|
const autorunUrl = new URL(
|
||||||
(cliArguments.ssl ? 'https://' : 'http://') +
|
(cliArguments.ssl ? 'https://' : 'http://') +
|
||||||
(getAutorunHostname(useIPv6, useIPv4)) +
|
(await getAutorunHostname(useIPv6, useIPv4)) +
|
||||||
(':') +
|
(':') +
|
||||||
((autorunPortOverride >= 0) ? autorunPortOverride : server_port),
|
((autorunPortOverride >= 0) ? autorunPortOverride : server_port),
|
||||||
);
|
);
|
||||||
@ -1045,6 +1042,7 @@ async function startServer() {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const [v6Failed, v4Failed] = await startHTTPorHTTPS(useIPv6, useIPv4);
|
const [v6Failed, v4Failed] = await startHTTPorHTTPS(useIPv6, useIPv4);
|
||||||
|
|
||||||
handleServerListenFail(v6Failed, v4Failed, useIPv6, useIPv4);
|
handleServerListenFail(v6Failed, v4Failed, useIPv6, useIPv4);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user