Compare commits

..

2 Commits

Author SHA1 Message Date
Gauthier
906ca61b60 fix: bypass cacheable-lookup when resolving localhost 2024-06-13 00:14:30 +02:00
fallenbagel
0342127058 fix: bypass cache-able lookups when resolving localhost 2024-06-13 01:13:07 +05:00
2 changed files with 14 additions and 11 deletions

View File

@@ -133,11 +133,6 @@ class JellyfinAPI extends ExternalAPI {
}
: {};
logger.debug(`Logging in to Jellyfin server: ${this.jellyfinHost}`, {
label: 'Jellyfin API',
clientIp: ClientIP,
});
const authResponse = await this.post<JellyfinLoginResponse>(
'/Users/AuthenticateByName',
{
@@ -151,12 +146,6 @@ class JellyfinAPI extends ExternalAPI {
return authResponse;
} catch (e) {
logger.error('Failed to login to Jellyfin server', {
label: 'Jellyfin API',
clientIp: ClientIP,
error: e,
});
const status = e.response?.status;
const networkErrorCodes = new Set([

View File

@@ -27,6 +27,7 @@ import type CacheableLookupType from 'cacheable-lookup';
import { TypeormStore } from 'connect-typeorm/out';
import cookieParser from 'cookie-parser';
import csurf from 'csurf';
import { lookup } from 'dns';
import type { NextFunction, Request, Response } from 'express';
import express from 'express';
import * as OpenApiValidator from 'express-openapi-validator';
@@ -54,6 +55,19 @@ app
const CacheableLookup = (await _importDynamic('cacheable-lookup'))
.default as typeof CacheableLookupType;
const cacheable = new CacheableLookup();
const originalLookup = cacheable.lookup;
// if hostname is localhost use dns.lookup instead of cacheable-lookup
cacheable.lookup = (...args: any) => {
const [hostname] = args;
if (hostname === 'localhost') {
lookup(...(args as Parameters<typeof lookup>));
} else {
originalLookup(...(args as Parameters<typeof originalLookup>));
}
};
cacheable.install(http.globalAgent);
cacheable.install(https.globalAgent);