server.js 1012 B

12345678910111213141516171819202122232425262728293031323334
  1. const express = require('express');
  2. const { createProxyMiddleware } = require('http-proxy-middleware');
  3. const path = require('path');
  4. const app = express();
  5. const PORT = 8090;
  6. // 代理 API 请求
  7. app.use('/iris-api', createProxyMiddleware({
  8. target: 'http://111.229.137.113:52773/csp/drg/sysInternalMutiple',
  9. changeOrigin: true,
  10. pathRewrite: {
  11. '^/iris-api': ''
  12. },
  13. onProxyRes: function(proxyRes, req, res) {
  14. proxyRes.headers['Access-Control-Allow-Origin'] = '*';
  15. },
  16. onError: function(err, req, res) {
  17. console.error('Proxy error:', err);
  18. res.status(500).json({ errorCode: '-1', errorMessage: '代理错误' });
  19. }
  20. }));
  21. // 静态文件
  22. app.use(express.static('C:\\inetpub\\wwwroot\\DRG'));
  23. // SPA 回退 - 使用正则表达式匹配所有路径
  24. app.use((req, res) => {
  25. res.sendFile(path.join('C:\\inetpub\\wwwroot\\DRG', 'index.html'));
  26. });
  27. app.listen(PORT, '0.0.0.0', () => {
  28. console.log('Server running on http://0.0.0.0:' + PORT);
  29. });