• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

chimurai / http-proxy-middleware / 4358068220

pending completion
4358068220

push

github

chimurai
refactor: minor type improvements

161 of 166 branches covered (96.99%)

6 of 6 new or added lines in 2 files covered. (100.0%)

368 of 376 relevant lines covered (97.87%)

24.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.0
/src/plugins/default/debug-proxy-errors-plugin.ts
1
import { Debug } from '../../debug';
12✔
2
import { Plugin } from '../../types';
3

4
const debug = Debug.extend('debug-proxy-errors-plugin');
12✔
5

6
/**
7
 * Subscribe to {@link https://www.npmjs.com/package/http-proxy#listening-for-proxy-events http-proxy error events} to prevent server from crashing.
8
 * Errors are logged with {@link https://www.npmjs.com/package/debug debug} library.
9
 */
10
export const debugProxyErrorsPlugin: Plugin = (proxyServer): void => {
12✔
11
  /**
12
   * http-proxy doesn't handle any errors by default (https://github.com/http-party/node-http-proxy#listening-for-proxy-events)
13
   * Prevent server from crashing when http-proxy errors (uncaught errors)
14
   */
15
  proxyServer.on('error', (error, req, res, target) => {
70✔
16
    debug(`http-proxy error event: \n%O`, error);
5✔
17
  });
18

19
  proxyServer.on('proxyReq', (proxyReq, req, socket) => {
70✔
20
    socket.on('error', (error) => {
46✔
21
      debug('Socket error in proxyReq event: \n%O', error);
×
22
    });
23
  });
24

25
  /**
26
   * Fix SSE close events
27
   * @link https://github.com/chimurai/http-proxy-middleware/issues/678
28
   * @link https://github.com/http-party/node-http-proxy/issues/1520#issue-877626125
29
   */
30
  proxyServer.on('proxyRes', (proxyRes, req, res) => {
70✔
31
    res.on('close', () => {
42✔
32
      if (!res.writableEnded) {
42!
33
        debug('Destroying proxyRes in proxyRes close event');
×
34
        proxyRes.destroy();
×
35
      }
36
    });
37
  });
38

39
  /**
40
   * Fix crash when target server restarts
41
   * https://github.com/chimurai/http-proxy-middleware/issues/476#issuecomment-746329030
42
   * https://github.com/webpack/webpack-dev-server/issues/1642#issuecomment-790602225
43
   */
44
  proxyServer.on('proxyReqWs', (proxyReq, req, socket) => {
70✔
45
    socket.on('error', (error) => {
3✔
46
      debug('Socket error in proxyReqWs event: \n%O', error);
×
47
    });
48
  });
49

50
  proxyServer.on('open', (proxySocket) => {
70✔
51
    proxySocket.on('error', (error) => {
3✔
52
      debug('Socket error in open event: \n%O', error);
×
53
    });
54
  });
55

56
  proxyServer.on('close', (req, socket, head) => {
70✔
57
    socket.on('error', (error) => {
3✔
58
      debug('Socket error in close event: \n%O', error);
×
59
    });
60
  });
61

62
  // https://github.com/webpack/webpack-dev-server/issues/1642#issuecomment-1103136590
63
  proxyServer.on('econnreset', (error, req, res, target) => {
70✔
64
    debug(`http-proxy econnreset event: \n%O`, error);
×
65
  });
66
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc