|
@@ -18,7 +18,7 @@ import {
|
|
ReqHeaderMiddleware,
|
|
ReqHeaderMiddleware,
|
|
} from './middlewares';
|
|
} from './middlewares';
|
|
|
|
|
|
-import { getDirectories, getDirectoriesSync, generateCfgs } from './utils';
|
|
|
|
|
|
+// import { getDirectories, getDirectoriesSync, generateCfgs } from './utils';
|
|
import * as path from 'path';
|
|
import * as path from 'path';
|
|
import chalk from 'chalk';
|
|
import chalk from 'chalk';
|
|
import { surveSwaggerSpecification } from './swagger';
|
|
import { surveSwaggerSpecification } from './swagger';
|
|
@@ -26,10 +26,6 @@ import swaggerUi from 'swagger-ui-express';
|
|
import LruCache from 'lru-cache';
|
|
import LruCache from 'lru-cache';
|
|
import { EXPIRED_TIME, INSIGHT_CACHE } from './utils/Const';
|
|
import { EXPIRED_TIME, INSIGHT_CACHE } from './utils/Const';
|
|
|
|
|
|
-const PLUGIN_DEV = process.env?.PLUGIN_DEV;
|
|
|
|
-const SRC_PLUGIN_DIR = 'src/plugins';
|
|
|
|
-const DEV_PLUGIN_DIR = '../../src/*/server';
|
|
|
|
-
|
|
|
|
const insightCache = new LruCache({
|
|
const insightCache = new LruCache({
|
|
maxAge: EXPIRED_TIME,
|
|
maxAge: EXPIRED_TIME,
|
|
updateAgeOnGet: true,
|
|
updateAgeOnGet: true,
|
|
@@ -39,13 +35,6 @@ export const app = express();
|
|
const PORT = 3000;
|
|
const PORT = 3000;
|
|
// initialize a simple http server
|
|
// initialize a simple http server
|
|
const server = http.createServer(app);
|
|
const server = http.createServer(app);
|
|
-// initialize the WebSocket server instance
|
|
|
|
-const io = new Server(server, {
|
|
|
|
- cors: {
|
|
|
|
- origin: '*',
|
|
|
|
- methods: ['GET', 'POST'],
|
|
|
|
- },
|
|
|
|
-});
|
|
|
|
|
|
|
|
app.set(INSIGHT_CACHE, insightCache);
|
|
app.set(INSIGHT_CACHE, insightCache);
|
|
// https://expressjs.com/en/resources/middleware/cors.html
|
|
// https://expressjs.com/en/resources/middleware/cors.html
|
|
@@ -68,81 +57,57 @@ app.use(ReqHeaderMiddleware);
|
|
const router = express.Router();
|
|
const router = express.Router();
|
|
const pluginsRouter = 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 });
|
|
|
|
- });
|
|
|
|
- pubSub.on('ws_pubsub', msg => {
|
|
|
|
- const { event, data } = msg;
|
|
|
|
- socket.emit(event, data);
|
|
|
|
- });
|
|
|
|
-});
|
|
|
|
|
|
+router.use('/milvus', connectRouter);
|
|
|
|
+router.use('/collections', collectionsRouter);
|
|
|
|
+router.use('/partitions', partitionsRouter);
|
|
|
|
+router.use('/schema', schemaRouter);
|
|
|
|
+router.use('/crons', cronsRouter);
|
|
|
|
+router.use('/users', userRouter);
|
|
|
|
|
|
-// Read plugin files and start express server
|
|
|
|
-// Import all plguins under "src/plugins"
|
|
|
|
-getDirectories(SRC_PLUGIN_DIR, async (dirErr: Error, dirRes: string[]) => {
|
|
|
|
- const cfgs: any[] = [];
|
|
|
|
- if (dirErr) {
|
|
|
|
- console.log('Reading plugin directory Error', dirErr);
|
|
|
|
- } else {
|
|
|
|
- generateCfgs(cfgs, dirRes);
|
|
|
|
- }
|
|
|
|
- // If under plugin dev mode, import all plugins under "../../src/*/server"
|
|
|
|
- if (PLUGIN_DEV) {
|
|
|
|
- getDirectoriesSync(
|
|
|
|
- DEV_PLUGIN_DIR,
|
|
|
|
- (devDirErr: Error, devDirRes: string[]) => {
|
|
|
|
- if (devDirErr) {
|
|
|
|
- console.log('Reading dev plugin directory Error', devDirErr);
|
|
|
|
- } else {
|
|
|
|
- generateCfgs(cfgs, devDirRes, false);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
- console.log('======/api/plugins configs======', cfgs);
|
|
|
|
- cfgs.forEach(async (cfg: any) => {
|
|
|
|
- const { api: pluginPath, componentPath } = cfg;
|
|
|
|
- if (!pluginPath) return;
|
|
|
|
- const {
|
|
|
|
- default: { router: pluginRouter },
|
|
|
|
- } = await import(componentPath);
|
|
|
|
- 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('/users', userRouter);
|
|
|
|
|
|
+router.get('/healthy', (req, res, next) => {
|
|
|
|
+ res.json({ status: 200 });
|
|
|
|
+ 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'));
|
|
|
|
|
|
- // Return client build files
|
|
|
|
- app.use(express.static('build'));
|
|
|
|
|
|
+const data = surveSwaggerSpecification();
|
|
|
|
+app.use('/api/v1/swagger', swaggerUi.serve, swaggerUi.setup(data));
|
|
|
|
|
|
- const data = surveSwaggerSpecification();
|
|
|
|
- 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'));
|
|
|
|
+});
|
|
|
|
|
|
- // 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'));
|
|
|
|
|
|
+// ErrorInterceptor
|
|
|
|
+app.use(ErrorMiddleware);
|
|
|
|
+
|
|
|
|
+// start server
|
|
|
|
+server.listen(PORT, () => {
|
|
|
|
+ // initialize the WebSocket server instance
|
|
|
|
+ const io = new Server(server, {
|
|
|
|
+ cors: {
|
|
|
|
+ origin: '*',
|
|
|
|
+ methods: ['GET', 'POST'],
|
|
|
|
+ },
|
|
});
|
|
});
|
|
-
|
|
|
|
- // ErrorInterceptor
|
|
|
|
- app.use(ErrorMiddleware);
|
|
|
|
- // start server
|
|
|
|
- server.listen(PORT, () => {
|
|
|
|
- console.log(chalk.green.bold(`Attu Server started on port ${PORT} :)`));
|
|
|
|
|
|
+ // Init WebSocket server event listener
|
|
|
|
+ io.on('connection', (socket: Socket) => {
|
|
|
|
+ console.info('ws connected');
|
|
|
|
+ socket.on('COLLECTION', (message: any) => {
|
|
|
|
+ socket.emit('COLLECTION', { data: message });
|
|
|
|
+ });
|
|
|
|
+ pubSub.on('ws_pubsub', (msg: any) => {
|
|
|
|
+ socket.emit(msg.event, msg.data);
|
|
|
|
+ });
|
|
|
|
+ io.on('disconnect', () => {
|
|
|
|
+ console.info('ws disconnected');
|
|
|
|
+ });
|
|
});
|
|
});
|
|
|
|
+ console.info(chalk.green.bold(`Attu Server started on port ${PORT} :)`));
|
|
});
|
|
});
|