How do I start gulp and json-server services at the same time?

  node.js, question

The project inside has installed gulp, started the service, and can access the static file html, but many interface calls want to simulate the interface with json-server, but I want to start both functions at the same time.
Either json-server is integrated into gulp, or the two services can be started at the same time, and under the same port, this is the key, and must be the same port, otherwise the interface call will cross domains.
How to operate?

The same port, certainly not.

I’ll give you a plan to use http-proxy-middleware plus proxy. child_process in gulp starts a process to run json-server. The following code is the code fragment in the actual project

...
 var proxyMiddleware = require('http-proxy-middleware');
 var child = require('child_process');
 
 ...
 ...
 ...
 
 gulp.task('dev:browser-sync', function(){
 //add proxy for gui
 var middleware = proxyMiddleware(['/user', '/persons'], {target: 'http://localhost:9001', changeOrigin: true});
 browserSync({
 server: {
 baseDir: './',
 index: 'build/login.html',
 middleware: middleware
 bracket
 });
 });
 gulp.task('dev:copy', ['dev:copy-html', 'dev:copy-conf', 'dev:copy-login', 'dev:copy-data']);
 gulp.task('dev', 'Run this for developing', ['dev:index', 'dev:copy', 'dev:browser-sync', 'dev:watch-files'], function(){
 //json-server --watch server/db.json  --port 9001
 var jsonServer = child.spawn('node_modules/json-server/bin/index.js', ['--watch', 'server/db.json', '--port', '9001']);
 jsonServer.stdout.on('data', function (data) {
 fs.writeFileSync("log/json-server.log", data.toString());
 });
 jsonServer.stderr.on('data', function (data) {
 Log ('stderr:' plus data');
 });
 jsonServer.on('exit', function (code) {
 Log ('childprocessexisting withcode' plus code);
 });
 });

Here’s another plan:
Use the concurrently method to start two commands, and then add the proxy to gulp

"dev": "concurrently \"gulp dev\" \"nodemon mock-server.js\"",

This plan can be referred tohttps://github.com/hjzheng/gulp-AngularJS1.x-seed