const express = require('express'); const webpack = require('webpack'); const webpackDevMiddleware = require('webpack-dev-middleware'); // const httpProxy = require("http-proxy"); var proxy = require('express-http-proxy'); const app = express(); const config = require('./webpack.remote.dev.js'); const compiler = webpack(config); const port = process.env.remoteDevPort; // var proxy = httpProxy.createProxyServer(); // Tell express to use the webpack-dev-middleware and use the webpack.config.js // configuration file as a base. app.use( webpackDevMiddleware(compiler, { publicPath: '/', }) ); const proxyUrls = ['/api', '/static', '/content', '/dashboard', '/assets', '/authApi', '/Dictionary', '/Files', '/WebSocket', '/TrainVideo']; proxyUrls.forEach(proxyUrl => { app.use(proxyUrl, proxy('http://localhost:10022', { proxyReqPathResolver: function(req) { // console.log(`请求的路径:${req.url}`); //请求的路径 return proxyUrl + `${req.url}` //转发请求路径 }, })); }); // Serve the files on port 8081. app.listen(port, function () { console.log('Example app listening on port ' + port + '!\n'); });