mirror of
https://github.com/langgenius/dify.git
synced 2026-04-15 00:51:22 +08:00
refactor(fetch): convert baseOptions to a function for dynamic request options
This commit is contained in:
parent
73d4bb596a
commit
55f96a4266
@ -23,7 +23,7 @@ import type {
|
||||
} from '@/types/workflow'
|
||||
import { removeAccessToken } from '@/app/components/share/utils'
|
||||
import type { FetchOptionType, ResponseError } from './fetch'
|
||||
import { ContentType, base, baseOptions, getAccessToken } from './fetch'
|
||||
import { ContentType, base, getAccessToken, getBaseOptions } from './fetch'
|
||||
import { asyncRunSafe } from '@/utils'
|
||||
import type {
|
||||
DataSourceNodeCompletedResponse,
|
||||
@ -400,6 +400,7 @@ export const ssePost = async (
|
||||
|
||||
const token = localStorage.getItem('console_token')
|
||||
|
||||
const baseOptions = getBaseOptions()
|
||||
const options = Object.assign({}, baseOptions, {
|
||||
method: 'POST',
|
||||
signal: abortController.signal,
|
||||
|
||||
@ -111,7 +111,7 @@ const baseClient = ky.create({
|
||||
timeout: TIME_OUT,
|
||||
})
|
||||
|
||||
export const baseOptions: RequestInit = {
|
||||
export const getBaseOptions = (): RequestInit => ({
|
||||
method: 'GET',
|
||||
mode: 'cors',
|
||||
credentials: 'include', // always send cookies、HTTP Basic authentication.
|
||||
@ -119,9 +119,10 @@ export const baseOptions: RequestInit = {
|
||||
'Content-Type': ContentType.json,
|
||||
}),
|
||||
redirect: 'follow',
|
||||
}
|
||||
})
|
||||
|
||||
async function base<T>(url: string, options: FetchOptionType = {}, otherOptions: IOtherOptions = {}): Promise<T> {
|
||||
const baseOptions = getBaseOptions()
|
||||
const { params, body, headers, ...init } = Object.assign({}, baseOptions, options)
|
||||
const {
|
||||
isPublicAPI = false,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user