server.js 1.1 KB

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