mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-19 01:54:04 +00:00
Add IPv6 support for hostnames (#807)
This commit is contained in:
@@ -2,6 +2,7 @@ import { AuthUserTypeEnum } from '@fastgpt/global/support/permission/constant';
|
|||||||
import { parseHeaderCert } from '../controller';
|
import { parseHeaderCert } from '../controller';
|
||||||
import { AuthModeType } from '../type';
|
import { AuthModeType } from '../type';
|
||||||
import { authOutLinkValid } from './outLink';
|
import { authOutLinkValid } from './outLink';
|
||||||
|
import { isIPv6 } from 'net';
|
||||||
|
|
||||||
export const authCert = async (props: AuthModeType) => {
|
export const authCert = async (props: AuthModeType) => {
|
||||||
const result = await parseHeaderCert(props);
|
const result = await parseHeaderCert(props);
|
||||||
@@ -34,7 +35,11 @@ export async function authCertOrShareId({
|
|||||||
|
|
||||||
/* auth the request from local service */
|
/* auth the request from local service */
|
||||||
export const authRequestFromLocal = ({ req }: AuthModeType) => {
|
export const authRequestFromLocal = ({ req }: AuthModeType) => {
|
||||||
const host = `${process.env.HOSTNAME || 'localhost'}:${process.env.PORT || 3000}`;
|
const host =
|
||||||
|
process.env.HOSTNAME && isIPv6(process.env.HOSTNAME)
|
||||||
|
? `[${process.env.HOSTNAME}]:${process.env.PORT || 3000}`
|
||||||
|
: `${process.env.HOSTNAME || 'localhost'}:${process.env.PORT || 3000}`;
|
||||||
|
|
||||||
if (host !== req.headers.host) {
|
if (host !== req.headers.host) {
|
||||||
return Promise.reject('Invalid request');
|
return Promise.reject('Invalid request');
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import axios, { Method, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
|
import axios, { Method, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
|
||||||
|
import { isIPv6 } from 'net';
|
||||||
interface ConfigType {
|
interface ConfigType {
|
||||||
headers?: { [key: string]: string };
|
headers?: { [key: string]: string };
|
||||||
hold?: boolean;
|
hold?: boolean;
|
||||||
@@ -78,7 +78,12 @@ export function request(url: string, data: any, config: ConfigType, method: Meth
|
|||||||
|
|
||||||
return instance
|
return instance
|
||||||
.request({
|
.request({
|
||||||
baseURL: `http://${process.env.HOSTNAME || 'localhost'}:${process.env.PORT || 3000}`,
|
baseURL: `http://${
|
||||||
|
process.env.HOSTNAME && isIPv6(process.env.HOSTNAME)
|
||||||
|
? `[${process.env.HOSTNAME}]:${process.env.PORT || 3000}`
|
||||||
|
: `${process.env.HOSTNAME || 'localhost'}:${process.env.PORT || 3000}`
|
||||||
|
}`,
|
||||||
|
|
||||||
url,
|
url,
|
||||||
method,
|
method,
|
||||||
data: ['POST', 'PUT'].includes(method) ? data : null,
|
data: ['POST', 'PUT'].includes(method) ? data : null,
|
||||||
|
@@ -3,6 +3,7 @@ import type { ModuleDispatchProps } from '@fastgpt/global/core/module/type.d';
|
|||||||
import { ModuleInputKeyEnum, ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants';
|
import { ModuleInputKeyEnum, ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { flatDynamicParams } from '../utils';
|
import { flatDynamicParams } from '../utils';
|
||||||
|
import { isIPv6 } from 'net';
|
||||||
|
|
||||||
export type HttpRequestProps = ModuleDispatchProps<{
|
export type HttpRequestProps = ModuleDispatchProps<{
|
||||||
[ModuleInputKeyEnum.abandon_httpUrl]: string;
|
[ModuleInputKeyEnum.abandon_httpUrl]: string;
|
||||||
@@ -132,7 +133,12 @@ async function fetchData({
|
|||||||
}): Promise<Record<string, any>> {
|
}): Promise<Record<string, any>> {
|
||||||
const { data: response } = await axios<Record<string, any>>({
|
const { data: response } = await axios<Record<string, any>>({
|
||||||
method,
|
method,
|
||||||
baseURL: `http://${process.env.HOSTNAME || 'localhost'}:${process.env.PORT || 3000}`,
|
baseURL: `http://${
|
||||||
|
process.env.HOSTNAME && isIPv6(process.env.HOSTNAME)
|
||||||
|
? `[${process.env.HOSTNAME}]:${process.env.PORT || 3000}`
|
||||||
|
: `${process.env.HOSTNAME || 'localhost'}:${process.env.PORT || 3000}`
|
||||||
|
}`,
|
||||||
|
|
||||||
url,
|
url,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
Reference in New Issue
Block a user