feat: add ignore tls error and make sure get tls info every times
This commit is contained in:
parent
4529dbca75
commit
d5a7a5d655
@ -1,4 +1,4 @@
|
||||
import { Form, Input, Select } from 'antd';
|
||||
import { Form, Input, Select, Switch } from 'antd';
|
||||
import React from 'react';
|
||||
import { MonitorOverviewComponent, MonitorProvider } from './types';
|
||||
import { trpc } from '../../../../api/trpc';
|
||||
@ -32,6 +32,13 @@ const MonitorHttp: React.FC = React.memo(() => {
|
||||
<Select.Option value="options">OPTIONS</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Ignore TLS/SSL error"
|
||||
valuePropName="checked"
|
||||
name={['payload', 'ignoreTLS']}
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Content-Type"
|
||||
name={['payload', 'contentType']}
|
||||
|
@ -3,6 +3,7 @@ import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
import { logger } from '../../../utils/logger';
|
||||
import dayjs from 'dayjs';
|
||||
import { prisma } from '../../_client';
|
||||
import https from 'https';
|
||||
|
||||
export const http: MonitorProvider<{
|
||||
url: string;
|
||||
@ -11,6 +12,7 @@ export const http: MonitorProvider<{
|
||||
contentType?: string;
|
||||
bodyValue?: string;
|
||||
maxRedirects?: number;
|
||||
ignoreTLS?: boolean;
|
||||
}> = {
|
||||
run: async (monitor) => {
|
||||
if (typeof monitor.payload !== 'object') {
|
||||
@ -24,6 +26,7 @@ export const http: MonitorProvider<{
|
||||
contentType,
|
||||
bodyValue,
|
||||
maxRedirects,
|
||||
ignoreTLS,
|
||||
} = monitor.payload;
|
||||
|
||||
const config: AxiosRequestConfig = {
|
||||
@ -45,9 +48,16 @@ export const http: MonitorProvider<{
|
||||
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 {
|
||||
const startTime = dayjs();
|
||||
const res = await axios(config);
|
||||
const res = await axios({ ...config });
|
||||
|
||||
const diff = dayjs().diff(startTime, 'ms');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user