From 0df76e75adbf3b3b369722a36696699a8e309978 Mon Sep 17 00:00:00 2001 From: Hans Chan Date: Wed, 14 Jul 2021 20:02:05 +0800 Subject: [PATCH] feat(cli): use same server in dev and editor --- packages/cli/src/cmd/editor/build.js | 3 +++ packages/cli/src/cmd/editor/index.js | 2 +- packages/cli/src/utils/server/index.js | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/cmd/editor/build.js b/packages/cli/src/cmd/editor/build.js index 1b540ec..f2bde6a 100644 --- a/packages/cli/src/cmd/editor/build.js +++ b/packages/cli/src/cmd/editor/build.js @@ -27,4 +27,7 @@ require('esbuild') }), ], }) + .then(() => { + console.log('imove editor builded'); + }) .catch(() => process.exit(1)); diff --git a/packages/cli/src/cmd/editor/index.js b/packages/cli/src/cmd/editor/index.js index e356e34..7275fc4 100644 --- a/packages/cli/src/cmd/editor/index.js +++ b/packages/cli/src/cmd/editor/index.js @@ -69,7 +69,7 @@ class Editor extends Base { } run() { - const server = createServer(8000); + const server = createServer(); server.use(express.static(path.join(__dirname, './template'))); server.post('/api/queryGraph', this.queryGraph.bind(this)); server.post('/api/modifyGraph', this.modifyGraph.bind(this)); diff --git a/packages/cli/src/utils/server/index.js b/packages/cli/src/utils/server/index.js index 3dec508..3cd7a1e 100644 --- a/packages/cli/src/utils/server/index.js +++ b/packages/cli/src/utils/server/index.js @@ -1,8 +1,15 @@ const express = require('express'); const bodyParser = require('body-parser'); +const cachedServer = {}; + const createServer = (port = 3500) => { + if (cachedServer[port]) { + return cachedServer[port]; + } const app = express(); + cachedServer[port] = app; + app.use(bodyParser.json({ limit: '50mb' })); app.use(bodyParser.urlencoded({ extended: false })); app.use((req, res, next) => {