diff --git a/src/common/axios.js b/src/common/axios.js index 61705539..81cc0602 100644 --- a/src/common/axios.js +++ b/src/common/axios.js @@ -2,7 +2,26 @@ import axios from 'axios'; import { getBaseURL } from './utils'; import { bigIntJSON } from './bigIntJSON'; -function setupAxios({ apiKey }) { +export const axiosInstance = axios.create({ + baseURL: process.env.NODE_ENV === 'development' ? 'http://localhost:6333' : getBaseURL(), + transformRequest: [ + function (data, headers) { + if (data instanceof FormData) { + return data; + } + headers['Content-Type'] = 'application/json'; + headers['x-inference-proxy'] = 'true'; + return bigIntJSON.stringify(data); + }, + ], + transformResponse: [ + function (data) { + return bigIntJSON.parse(data); + }, + ], +}); + +export function setupAxios(axios, { apiKey }) { if (process.env.NODE_ENV === 'development') { axios.defaults.baseURL = 'http://localhost:6333'; } else { @@ -27,5 +46,3 @@ function setupAxios({ apiKey }) { }, ]; } - -export default setupAxios; diff --git a/src/components/CodeEditorWindow/config/RequesFromCode.js b/src/components/CodeEditorWindow/config/RequesFromCode.js index a79dd098..a1c7c263 100644 --- a/src/components/CodeEditorWindow/config/RequesFromCode.js +++ b/src/components/CodeEditorWindow/config/RequesFromCode.js @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance as axios } from '../../../common/axios'; import { stripComments } from 'jsonc-parser'; import { updateHistory } from '../../../lib/update-history'; import { bigIntJSON } from '../../../common/bigIntJSON'; diff --git a/src/components/Notifications.jsx b/src/components/Notifications.jsx index a4f2a760..0e51eff3 100644 --- a/src/components/Notifications.jsx +++ b/src/components/Notifications.jsx @@ -10,7 +10,7 @@ import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline'; import List from '@mui/material/List'; import MuiListItem from '@mui/material/ListItem'; import MuiDivider from '@mui/material/Divider'; -import axios from 'axios'; +import { axiosInstance as axios } from '../common/axios'; import { CodeBlock } from './Common/CodeBlock'; import { Box, Button, Chip, Drawer, useMediaQuery } from '@mui/material'; import { requestFromCode } from './CodeEditorWindow/config/RequesFromCode'; @@ -69,6 +69,10 @@ export default function Notifications() { React.useEffect(() => { setLoading(true); fetchNotifications().then((data) => { + if (!data || data.length === 0) { + setLoading(false); + return; + } setIssuesCount(data.length); setIssues(data); setLoading(false); diff --git a/src/context/client-context.jsx b/src/context/client-context.jsx index c59b80c7..c2a4c795 100644 --- a/src/context/client-context.jsx +++ b/src/context/client-context.jsx @@ -1,5 +1,5 @@ import React, { useContext, createContext, useState, useEffect } from 'react'; -import setupAxios from '../common/axios'; +import { axiosInstance, setupAxios } from '../common/axios'; import qdrantClient from '../common/client'; import { bigIntJSON } from '../common/bigIntJSON'; @@ -35,7 +35,7 @@ export const ClientProvider = (props) => { const client = qdrantClient(settings); useEffect(() => { - setupAxios(settings); + setupAxios(axiosInstance, settings); persistSettings(settings); }, [settings]);