Skip to content

Commit

Permalink
fix: use undici proxy agent
Browse files Browse the repository at this point in the history
  • Loading branch information
gauthier-th committed Oct 22, 2024
1 parent daecb6b commit 4e74105
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 104 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"express-session": "1.17.3",
"formik": "^2.4.6",
"gravatar-url": "3.1.0",
"https-proxy-agent": "^7.0.5",
"lodash": "4.17.21",
"mime": "3",
"next": "^14.2.4",
Expand Down Expand Up @@ -94,7 +93,8 @@
"sqlite3": "5.1.4",
"swagger-ui-express": "4.6.2",
"swr": "2.2.5",
"typeorm": "0.3.12",
"typeorm": "0.3.11",
"undici": "^6.20.1",
"web-push": "3.5.0",
"winston": "3.8.2",
"winston-daily-rotate-file": "4.7.1",
Expand Down
60 changes: 23 additions & 37 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 2 additions & 19 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import routes from '@server/routes';
import avatarproxy from '@server/routes/avatarproxy';
import imageproxy from '@server/routes/imageproxy';
import { getAppVersion } from '@server/utils/appVersion';
import bindHttpMethod from '@server/utils/bindHttpMethod';
import restartFlag from '@server/utils/restartFlag';
import { getClientIp } from '@supercharge/request-ip';
import { TypeormStore } from 'connect-typeorm/out';
Expand All @@ -33,14 +32,12 @@ import express from 'express';
import * as OpenApiValidator from 'express-openapi-validator';
import type { Store } from 'express-session';
import session from 'express-session';
import http from 'http';
import https from 'https';
import { HttpsProxyAgent } from 'https-proxy-agent';
import next from 'next';
import dns from 'node:dns';
import net from 'node:net';
import path from 'path';
import swaggerUi from 'swagger-ui-express';
import { ProxyAgent, setGlobalDispatcher } from 'undici';
import YAML from 'yamljs';

if (process.env.forceIpv4First === 'true') {
Expand Down Expand Up @@ -73,21 +70,7 @@ app

// Register HTTP proxy
if (settings.main.httpProxy) {
const agent = new HttpsProxyAgent(settings.main.httpProxy);

(globalThis as any)[Symbol.for('undici.globalDispatcher.1')] = agent;

http.globalAgent = agent;
https.globalAgent = agent;

const httpGet = http.get;
const httpRequest = http.request;
const httpsGet = https.get;
const httpsRequest = https.request;
http.get = bindHttpMethod(httpGet, agent);
http.request = bindHttpMethod(httpRequest, agent);
https.get = bindHttpMethod(httpsGet, agent);
https.request = bindHttpMethod(httpsRequest, agent);
setGlobalDispatcher(new ProxyAgent(settings.main.httpProxy));
}

// Migrate library types
Expand Down
46 changes: 0 additions & 46 deletions server/utils/bindHttpMethod.ts

This file was deleted.

0 comments on commit 4e74105

Please sign in to comment.