Browse Source

feat(cli): use same server in dev and editor

master
Hans Chan 4 years ago
parent
commit
0df76e75ad
  1. 3
      packages/cli/src/cmd/editor/build.js
  2. 2
      packages/cli/src/cmd/editor/index.js
  3. 7
      packages/cli/src/utils/server/index.js

3
packages/cli/src/cmd/editor/build.js

@ -27,4 +27,7 @@ require('esbuild')
}),
],
})
.then(() => {
console.log('imove editor builded');
})
.catch(() => process.exit(1));

2
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));

7
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) => {

Loading…
Cancel
Save