Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: disable remote debugger by default #17498

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { ofetch } from 'ofetch';
let envs = process.env;

export type Config = {
// app config
disallowRobot: boolean;
enableCluster?: string;
isPackage: boolean;
nodeName?: string;
puppeteerWSEndpoint?: string;
chromiumExecutablePath?: string;
// network
connect: {
port: number;
};
Expand All @@ -20,6 +22,7 @@ export type Config = {
ua: string;
trueUA: string;
allowOrigin?: string;
// cache
cache: {
type: string;
requestTimeout: number;
Expand All @@ -32,6 +35,7 @@ export type Config = {
redis: {
url: string;
};
// proxy
proxyUri?: string;
proxy: {
protocol?: string;
Expand All @@ -43,7 +47,9 @@ export type Config = {
};
pacUri?: string;
pacScript?: string;
// access control
accessKey?: string;
// logging
debugInfo: string;
loggerLevel: string;
noLogfiles?: boolean;
Expand All @@ -56,6 +62,8 @@ export type Config = {
dsn?: string;
routeTimeout: number;
};
enableRemoteDebugging?: boolean;
// feed config
hotlink: {
template?: string;
includePaths?: string[];
Expand All @@ -78,6 +86,8 @@ export type Config = {
promptTitle: string;
promptDescription: string;
};

// Route-specific Configurations
bilibili: {
cookies: Record<string, string | undefined>;
dmImgList?: string;
Expand Down Expand Up @@ -426,7 +436,6 @@ const calculateValue = () => {
requestTimeout: toInt(envs.REQUEST_TIMEOUT, 30000), // Milliseconds to wait for the server to end the response before aborting the request
ua: envs.UA ?? (toBoolean(envs.NO_RANDOM_UA, false) ? TRUE_UA : randUserAgent({ browser: 'chrome', os: 'mac os', device: 'desktop' })),
trueUA: TRUE_UA,
// cors request
allowOrigin: envs.ALLOW_ORIGIN,
// cache
cache: {
Expand Down Expand Up @@ -470,6 +479,7 @@ const calculateValue = () => {
dsn: envs.SENTRY,
routeTimeout: toInt(envs.SENTRY_ROUTE_TIMEOUT, 30000),
},
enableRemoteDebugging: toBoolean(envs.ENABLE_REMOTE_DEBUGGING, false),
// feed config
hotlink: {
template: envs.HOTLINK_TEMPLATE,
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/ofetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { config } from '@/config';
import logger from '@/utils/logger';
import { register } from 'node-network-devtools';

process.env.NODE_ENV === 'dev' && register();
config.enableRemoteDebugging && process.env.NODE_ENV === 'dev' && register();

const rofetch = createFetch().create({
retryStatusCodes: [400, 408, 409, 425, 429, 500, 502, 503, 504],
Expand Down
1 change: 1 addition & 0 deletions lib/utils/request-rewriter/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('useCustomHeader', () => {

beforeEach(() => {
originalEnv = process.env.NODE_ENV || Env.test;
process.env.ENABLE_REMOTE_DEBUGGING = 'true';
});

afterEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/request-rewriter/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const limiter = new RateLimiterMemory({
});

const limiterQueue = new RateLimiterQueue(limiter, {
maxQueueSize: 5000,
maxQueueSize: 4800,
});

export const useCustomHeader = (headers: Headers) => {
Expand Down Expand Up @@ -57,7 +57,7 @@ const wrappedFetch: typeof undici.fetch = async (input: RequestInfo, init?: Requ
request.headers.delete('x-prefer-proxy');
}

useCustomHeader(request.headers);
config.enableRemoteDebugging && useCustomHeader(request.headers);

// proxy
if (!init?.dispatcher && proxy.dispatcher && (proxy.proxyObj.strategy !== 'on_retry' || isRetry)) {
Expand Down
Loading