|
@@ -1,29 +1,30 @@
|
|
|
-import express from "express";
|
|
|
-import cors from "cors";
|
|
|
-import helmet from "helmet";
|
|
|
-import * as http from "http";
|
|
|
-import { Server, Socket } from "socket.io";
|
|
|
-import { router as connectRouter } from "./milvus";
|
|
|
-import { router as collectionsRouter } from "./collections";
|
|
|
-import { router as partitionsRouter } from "./partitions";
|
|
|
-import { router as schemaRouter } from "./schema";
|
|
|
-import { router as cronsRouter } from "./crons";
|
|
|
-import { pubSub } from "./events";
|
|
|
+import express from 'express';
|
|
|
+import cors from 'cors';
|
|
|
+import helmet from 'helmet';
|
|
|
+import * as http from 'http';
|
|
|
+import { Server, Socket } from 'socket.io';
|
|
|
+import { router as connectRouter } from './milvus';
|
|
|
+import { router as collectionsRouter } from './collections';
|
|
|
+import { router as partitionsRouter } from './partitions';
|
|
|
+import { router as schemaRouter } from './schema';
|
|
|
+import { router as cronsRouter } from './crons';
|
|
|
+import { pubSub } from './events';
|
|
|
import {
|
|
|
TransformResMiddlerware,
|
|
|
LoggingMiddleware,
|
|
|
ErrorMiddleware,
|
|
|
-} from "./middlewares";
|
|
|
+ ReqHeaderMiddleware,
|
|
|
+} from './middlewares';
|
|
|
|
|
|
-import { getDirectories, getDirectoriesSync, generateCfgs } from "./utils";
|
|
|
-import * as path from "path";
|
|
|
-import chalk from "chalk";
|
|
|
-import { surveSwaggerSpecification } from "./swagger";
|
|
|
-import swaggerUi from "swagger-ui-express";
|
|
|
+import { getDirectories, getDirectoriesSync, generateCfgs } from './utils';
|
|
|
+import * as path from 'path';
|
|
|
+import chalk from 'chalk';
|
|
|
+import { surveSwaggerSpecification } from './swagger';
|
|
|
+import swaggerUi from 'swagger-ui-express';
|
|
|
|
|
|
const PLUGIN_DEV = process.env?.PLUGIN_DEV;
|
|
|
-const SRC_PLUGIN_DIR = "src/plugins";
|
|
|
-const DEV_PLUGIN_DIR = "../../src/*/server";
|
|
|
+const SRC_PLUGIN_DIR = 'src/plugins';
|
|
|
+const DEV_PLUGIN_DIR = '../../src/*/server';
|
|
|
|
|
|
export const app = express();
|
|
|
const PORT = 3000;
|
|
@@ -32,8 +33,8 @@ const server = http.createServer(app);
|
|
|
// initialize the WebSocket server instance
|
|
|
const io = new Server(server, {
|
|
|
cors: {
|
|
|
- origin: "*",
|
|
|
- methods: ["GET", "POST"],
|
|
|
+ origin: '*',
|
|
|
+ methods: ['GET', 'POST'],
|
|
|
},
|
|
|
});
|
|
|
|
|
@@ -45,22 +46,25 @@ app.use(
|
|
|
contentSecurityPolicy: false,
|
|
|
})
|
|
|
);
|
|
|
-app.use(express.json({ limit: "150MB" }));
|
|
|
+app.use(express.json({ limit: '150MB' }));
|
|
|
// TransformResInterceptor
|
|
|
app.use(TransformResMiddlerware);
|
|
|
// LoggingInterceptor
|
|
|
app.use(LoggingMiddleware);
|
|
|
|
|
|
+// All headers operations
|
|
|
+app.use(ReqHeaderMiddleware);
|
|
|
+
|
|
|
const router = express.Router();
|
|
|
const pluginsRouter = express.Router();
|
|
|
|
|
|
// Init WebSocket server event listener
|
|
|
-io.on("connection", (socket: Socket) => {
|
|
|
- console.log("socket.io connected");
|
|
|
- socket.on("COLLECTION", (message: any) => {
|
|
|
- socket.emit("COLLECTION", { data: message });
|
|
|
+io.on('connection', (socket: Socket) => {
|
|
|
+ console.log('socket.io connected');
|
|
|
+ socket.on('COLLECTION', (message: any) => {
|
|
|
+ socket.emit('COLLECTION', { data: message });
|
|
|
});
|
|
|
- pubSub.on("ws_pubsub", (msg) => {
|
|
|
+ pubSub.on('ws_pubsub', (msg) => {
|
|
|
const { event, data } = msg;
|
|
|
socket.emit(event, data);
|
|
|
});
|
|
@@ -71,7 +75,7 @@ io.on("connection", (socket: Socket) => {
|
|
|
getDirectories(SRC_PLUGIN_DIR, async (dirErr: Error, dirRes: string[]) => {
|
|
|
const cfgs: any[] = [];
|
|
|
if (dirErr) {
|
|
|
- console.log("Reading plugin directory Error", dirErr);
|
|
|
+ console.log('Reading plugin directory Error', dirErr);
|
|
|
} else {
|
|
|
generateCfgs(cfgs, dirRes);
|
|
|
}
|
|
@@ -81,14 +85,14 @@ getDirectories(SRC_PLUGIN_DIR, async (dirErr: Error, dirRes: string[]) => {
|
|
|
DEV_PLUGIN_DIR,
|
|
|
(devDirErr: Error, devDirRes: string[]) => {
|
|
|
if (devDirErr) {
|
|
|
- console.log("Reading dev plugin directory Error", devDirErr);
|
|
|
+ console.log('Reading dev plugin directory Error', devDirErr);
|
|
|
} else {
|
|
|
generateCfgs(cfgs, devDirRes, false);
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
- console.log("======/api/plugins configs======", cfgs);
|
|
|
+ console.log('======/api/plugins configs======', cfgs);
|
|
|
cfgs.forEach(async (cfg: any) => {
|
|
|
const { api: pluginPath, componentPath } = cfg;
|
|
|
if (!pluginPath) return;
|
|
@@ -98,30 +102,30 @@ getDirectories(SRC_PLUGIN_DIR, async (dirErr: Error, dirRes: string[]) => {
|
|
|
pluginsRouter.use(`/${pluginPath}`, pluginRouter);
|
|
|
});
|
|
|
|
|
|
- router.use("/milvus", connectRouter);
|
|
|
- router.use("/collections", collectionsRouter);
|
|
|
- router.use("/partitions", partitionsRouter);
|
|
|
- router.use("/schema", schemaRouter);
|
|
|
- router.use("/crons", cronsRouter);
|
|
|
+ router.use('/milvus', connectRouter);
|
|
|
+ router.use('/collections', collectionsRouter);
|
|
|
+ router.use('/partitions', partitionsRouter);
|
|
|
+ router.use('/schema', schemaRouter);
|
|
|
+ router.use('/crons', cronsRouter);
|
|
|
|
|
|
- router.get("/healthy", (req, res, next) => {
|
|
|
+ router.get('/healthy', (req, res, next) => {
|
|
|
res.json({ status: 200 });
|
|
|
next();
|
|
|
});
|
|
|
|
|
|
- app.use("/api/v1", router);
|
|
|
- app.use("/api/plugins", pluginsRouter);
|
|
|
+ app.use('/api/v1', router);
|
|
|
+ app.use('/api/plugins', pluginsRouter);
|
|
|
|
|
|
// Return client build files
|
|
|
- app.use(express.static("build"));
|
|
|
+ app.use(express.static('build'));
|
|
|
|
|
|
const data = surveSwaggerSpecification();
|
|
|
- app.use("/api/v1/swagger", swaggerUi.serve, swaggerUi.setup(data));
|
|
|
+ app.use('/api/v1/swagger', swaggerUi.serve, swaggerUi.setup(data));
|
|
|
|
|
|
// handle every other route with index.html, which will contain
|
|
|
// a script tag to your application's JavaScript file(s).
|
|
|
- app.get("*", (request, response) => {
|
|
|
- response.sendFile(path.join(__dirname, "../build/index.html"));
|
|
|
+ app.get('*', (request, response) => {
|
|
|
+ response.sendFile(path.join(__dirname, '../build/index.html'));
|
|
|
});
|
|
|
|
|
|
// ErrorInterceptor
|