diff --git a/client/src/pages/connect/AuthForm.tsx b/client/src/pages/connect/AuthForm.tsx index 6679a9f4..8a9ee818 100644 --- a/client/src/pages/connect/AuthForm.tsx +++ b/client/src/pages/connect/AuthForm.tsx @@ -9,7 +9,6 @@ import { ITextfieldConfig } from '../../components/customInput/Types'; import { useFormValidation } from '../../hooks/Form'; import { formatForm } from '../../utils/Form'; import { MilvusHttp } from '../../http/Milvus'; -import { formatAddress } from '../../utils/Format'; import { useNavigate } from 'react-router-dom'; import { rootContext } from '../../context/Root'; import { authContext } from '../../context/Auth'; @@ -183,7 +182,7 @@ export const AuthForm = (props: any) => { const handleConnect = async (event: React.FormEvent) => { event.preventDefault(); - const address = formatAddress(form.address); + const address = form.address; const data = { ...form, address }; await MilvusHttp.connect(data); diff --git a/client/src/utils/Format.ts b/client/src/utils/Format.ts index 5b093123..250c40f0 100644 --- a/client/src/utils/Format.ts +++ b/client/src/utils/Format.ts @@ -144,7 +144,7 @@ export const getCreateFieldType = (config: Field): CreateFieldType => { // Trim the address export const formatAddress = (address: string): string => { // remove http or https prefix from address - const ip = address.replace(/(http|https):\/\//, ''); + const ip = address.replace(/(http):\/\//, ''); return ip.includes(':') ? ip : `${ip}:${DEFAULT_MILVUS_PORT}`; }; diff --git a/server/src/middlewares/index.ts b/server/src/middlewares/index.ts index f1445afc..8348344d 100644 --- a/server/src/middlewares/index.ts +++ b/server/src/middlewares/index.ts @@ -1,4 +1,4 @@ -import { Request, Response, NextFunction, Errback } from 'express'; +import { Request, Response, NextFunction } from 'express'; import morgan from 'morgan'; import chalk from 'chalk'; import { MilvusService } from '../milvus/milvus.service'; @@ -15,9 +15,8 @@ export const ReqHeaderMiddleware = ( const insightCache = req.app.get(INSIGHT_CACHE); // all ape requests need set milvus address in header. // server will set activeaddress in milvus service. - const milvusAddress = MilvusService.formatAddress( - (req.headers[MILVUS_ADDRESS] as string) || '' - ); + const milvusAddress = (req.headers[MILVUS_ADDRESS] as string) || ''; + // console.log('------ Request headers -------', req.headers); // only api request has MILVUS_ADDRESS. // When client run in express, we dont need static files like: xx.js run this logic. @@ -25,9 +24,7 @@ export const ReqHeaderMiddleware = ( if (milvusAddress && insightCache.has(milvusAddress)) { MilvusService.activeAddress = milvusAddress; // insight cache will update expire time when use insightCache.get - MilvusService.activeMilvusClient = insightCache.get( - MilvusService.formatAddress(milvusAddress) - ); + MilvusService.activeMilvusClient = insightCache.get(milvusAddress); } const CONNECT_URL = `/api/v1/milvus/connect`; @@ -35,7 +32,7 @@ export const ReqHeaderMiddleware = ( if (req.url !== CONNECT_URL && !MilvusService.activeMilvusClient) { throw HttpErrors( HTTP_STATUS_CODE.FORBIDDEN, - 'Can not find your connection, please connect Milvus again' + 'Can not find your connection, please check your connection settings.' ); } diff --git a/server/src/milvus/milvus.service.ts b/server/src/milvus/milvus.service.ts index 722eb894..2387860e 100644 --- a/server/src/milvus/milvus.service.ts +++ b/server/src/milvus/milvus.service.ts @@ -23,8 +23,8 @@ export class MilvusService { } static formatAddress(address: string) { - // remove http or https prefix from address - const ip = address.replace(/(http|https):\/\//, ''); + // remove http prefix from address + const ip = address.replace(/(http):\/\//, ''); return ip.includes(':') ? ip : `${ip}:${DEFAULT_MILVUS_PORT}`; } @@ -32,7 +32,7 @@ export class MilvusService { if (!MilvusService.activeMilvusClient) { throw HttpErrors( HTTP_STATUS_CODE.FORBIDDEN, - 'Can not find your connection, please connect Milvus again' + 'Can not find your connection, please check your connection settings.' ); // throw new Error('Please connect milvus first'); @@ -50,20 +50,17 @@ export class MilvusService { const { address, username, password } = data; // grpc only need address without http const milvusAddress = MilvusService.formatAddress(address); - const hasAuth = username !== undefined && password !== undefined; try { - const milvusClient: MilvusClient = hasAuth - ? new MilvusClient({ - address: milvusAddress, - username, - password, - }) - : new MilvusClient({ address }); + const milvusClient: MilvusClient = new MilvusClient({ + address: milvusAddress, + username, + password, + }); // don't break attu await milvusClient.connectPromise.catch(error => { - throw HttpErrors(HTTP_STATUS_CODE.BAD_REQUEST, error); + throw HttpErrors(HTTP_STATUS_CODE.FORBIDDEN, error); }); // check healthy @@ -78,8 +75,8 @@ export class MilvusService { } } catch (error) { // if milvus is not working, delete connection. - cache.del(address); - throw HttpErrors(HTTP_STATUS_CODE.BAD_REQUEST, error); + cache.dump(); + throw HttpErrors(HTTP_STATUS_CODE.FORBIDDEN, error); } }