feat: add ignore tls error and make sure get tls info every times

This commit is contained in:
moonrailgun 2023-11-02 00:20:48 +08:00
parent 4529dbca75
commit d5a7a5d655
2 changed files with 19 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { Form, Input, Select } from 'antd'; import { Form, Input, Select, Switch } from 'antd';
import React from 'react'; import React from 'react';
import { MonitorOverviewComponent, MonitorProvider } from './types'; import { MonitorOverviewComponent, MonitorProvider } from './types';
import { trpc } from '../../../../api/trpc'; import { trpc } from '../../../../api/trpc';
@ -32,6 +32,13 @@ const MonitorHttp: React.FC = React.memo(() => {
<Select.Option value="options">OPTIONS</Select.Option> <Select.Option value="options">OPTIONS</Select.Option>
</Select> </Select>
</Form.Item> </Form.Item>
<Form.Item
label="Ignore TLS/SSL error"
valuePropName="checked"
name={['payload', 'ignoreTLS']}
>
<Switch />
</Form.Item>
<Form.Item <Form.Item
label="Content-Type" label="Content-Type"
name={['payload', 'contentType']} name={['payload', 'contentType']}

View File

@ -3,6 +3,7 @@ import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import { logger } from '../../../utils/logger'; import { logger } from '../../../utils/logger';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { prisma } from '../../_client'; import { prisma } from '../../_client';
import https from 'https';
export const http: MonitorProvider<{ export const http: MonitorProvider<{
url: string; url: string;
@ -11,6 +12,7 @@ export const http: MonitorProvider<{
contentType?: string; contentType?: string;
bodyValue?: string; bodyValue?: string;
maxRedirects?: number; maxRedirects?: number;
ignoreTLS?: boolean;
}> = { }> = {
run: async (monitor) => { run: async (monitor) => {
if (typeof monitor.payload !== 'object') { if (typeof monitor.payload !== 'object') {
@ -24,6 +26,7 @@ export const http: MonitorProvider<{
contentType, contentType,
bodyValue, bodyValue,
maxRedirects, maxRedirects,
ignoreTLS,
} = monitor.payload; } = monitor.payload;
const config: AxiosRequestConfig = { const config: AxiosRequestConfig = {
@ -45,9 +48,16 @@ export const http: MonitorProvider<{
config.data = bodyValue; config.data = bodyValue;
} }
const httpsAgentOptions = {
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
rejectUnauthorized: !ignoreTLS,
};
config.httpsAgent = new https.Agent(httpsAgentOptions);
try { try {
const startTime = dayjs(); const startTime = dayjs();
const res = await axios(config); const res = await axios({ ...config });
const diff = dayjs().diff(startTime, 'ms'); const diff = dayjs().diff(startTime, 'ms');