server.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. const express = require('express');
  2. const webpack = require('webpack');
  3. const webpackDevMiddleware = require('webpack-dev-middleware');
  4. // const httpProxy = require("http-proxy");
  5. var proxy = require('express-http-proxy');
  6. const app = express();
  7. const config = require('./webpack.remote.dev.js');
  8. const compiler = webpack(config);
  9. const port = process.env.remoteDevPort;
  10. // var proxy = httpProxy.createProxyServer();
  11. // Tell express to use the webpack-dev-middleware and use the webpack.config.js
  12. // configuration file as a base.
  13. app.use(
  14. webpackDevMiddleware(compiler, {
  15. publicPath: '/',
  16. })
  17. );
  18. const proxyUrls = ['/api', '/static', '/content', '/dashboard', '/assets', '/authApi', '/Dictionary', '/Files', '/WebSocket', '/TrainVideo'];
  19. proxyUrls.forEach(proxyUrl => {
  20. app.use(proxyUrl, proxy('http://localhost:10022', {
  21. proxyReqPathResolver: function(req) {
  22. // console.log(`请求的路径:${req.url}`); //请求的路径
  23. return proxyUrl + `${req.url}` //转发请求路径
  24. },
  25. }));
  26. });
  27. // Serve the files on port 8081.
  28. app.listen(port, function () {
  29. console.log('Example app listening on port ' + port + '!\n');
  30. });