@@ -3,7 +3,33 @@ var historyApiFallback = require('connect-history-api-fallback');
3
3
var httpProxyMiddleware = require ( 'http-proxy-middleware' ) ;
4
4
var paths = require ( '../../config/paths' ) ;
5
5
6
- module . exports = function addMiddleware ( devServer ) {
6
+ // We need to provide a custom onError function for httpProxyMiddleware.
7
+ // It allows us to log custom error messages on the console.
8
+ function onProxyError ( proxy ) {
9
+ return function ( err , req , res ) {
10
+ var host = req . headers && req . headers . host ;
11
+ console . log (
12
+ chalk . red ( 'Proxy error:' ) + ' Could not proxy request ' + chalk . cyan ( req . url ) +
13
+ ' from ' + chalk . cyan ( host ) + ' to ' + chalk . cyan ( proxy ) + '.'
14
+ ) ;
15
+ console . log (
16
+ 'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
17
+ chalk . cyan ( err . code ) + ').'
18
+ ) ;
19
+ console . log ( ) ;
20
+
21
+ // And immediately send the proper error response to the client.
22
+ // Otherwise, the request will eventually timeout with ERR_EMPTY_RESPONSE on the client side.
23
+ if ( res . writeHead && ! res . headersSent ) {
24
+ res . writeHead ( 500 ) ;
25
+ }
26
+ res . end ( 'Proxy error: Could not proxy request ' + req . url + ' from ' +
27
+ host + ' to ' + proxy + ' (' + err . code + ').'
28
+ ) ;
29
+ }
30
+ }
31
+
32
+ module . exports = function addWebpackMiddleware ( devServer ) {
7
33
// `proxy` lets you to specify a fallback server during development.
8
34
// Every unrecognized request will be forwarded to it.
9
35
var proxy = require ( paths . appPackageJson ) . proxy ;
@@ -54,7 +80,8 @@ module.exports = function addMiddleware(devServer) {
54
80
onError : onProxyError ( proxy ) ,
55
81
secure : false ,
56
82
changeOrigin : true ,
57
- ws : true
83
+ ws : true ,
84
+ xfwd : true
58
85
} ) ;
59
86
devServer . use ( mayProxy , hpm ) ;
60
87
@@ -68,29 +95,3 @@ module.exports = function addMiddleware(devServer) {
68
95
// It may be /index.html, so let the dev server try serving it again.
69
96
devServer . use ( devServer . middleware ) ;
70
97
} ;
71
-
72
- // We need to provide a custom onError function for httpProxyMiddleware.
73
- // It allows us to log custom error messages on the console.
74
- function onProxyError ( proxy ) {
75
- return function ( err , req , res ) {
76
- var host = req . headers && req . headers . host ;
77
- console . log (
78
- chalk . red ( 'Proxy error:' ) + ' Could not proxy request ' + chalk . cyan ( req . url ) +
79
- ' from ' + chalk . cyan ( host ) + ' to ' + chalk . cyan ( proxy ) + '.'
80
- ) ;
81
- console . log (
82
- 'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
83
- chalk . cyan ( err . code ) + ').'
84
- ) ;
85
- console . log ( ) ;
86
-
87
- // And immediately send the proper error response to the client.
88
- // Otherwise, the request will eventually timeout with ERR_EMPTY_RESPONSE on the client side.
89
- if ( res . writeHead && ! res . headersSent ) {
90
- res . writeHead ( 500 ) ;
91
- }
92
- res . end ( 'Proxy error: Could not proxy request ' + req . url + ' from ' +
93
- host + ' to ' + proxy + ' (' + err . code + ').'
94
- ) ;
95
- }
96
- }
0 commit comments