index.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import express from "express";
  2. import { MilvusService } from "./milvus.service";
  3. const router = express.Router();
  4. const milvusService = new MilvusService();
  5. router.post("/connect", async (req, res, next) => {
  6. const address = req.body?.address;
  7. try {
  8. const result = await milvusService.connectMilvus(address);
  9. res.send(result);
  10. } catch (error) {
  11. next(error);
  12. }
  13. });
  14. router.get("/check", async (req, res, next) => {
  15. const address = "" + req.query?.address;
  16. try {
  17. const result = await milvusService.checkConnect(address);
  18. res.send(result);
  19. } catch (error) {
  20. next(error);
  21. }
  22. });
  23. router.put("/flush", async (req, res, next) => {
  24. const collectionNames = req.body;
  25. try {
  26. const result = await milvusService.flush(collectionNames);
  27. res.send(result);
  28. } catch (error) {
  29. next(error);
  30. }
  31. });
  32. router.get("/metrics", async (req, res, next) => {
  33. try {
  34. const result = await milvusService.getMetrics();
  35. res.send(result);
  36. } catch (error) {
  37. next(error);
  38. }
  39. });
  40. export { router, milvusService };