@@ -494,14 +494,50 @@ describe('http-proxy-middleware in actual server', function () {
494
494
} ) ;
495
495
} ) ;
496
496
497
+ describe ( 'express with path + proxy' , function ( ) {
498
+ var proxyServer , targetServer ;
499
+ var responseBody ;
500
+
501
+ beforeEach ( function ( done ) {
502
+ var mw_proxy = proxyMiddleware ( 'http://localhost:8000' ) ;
503
+ var mw_target = function ( req , res , next ) {
504
+ res . write ( req . url ) ; // respond with req.url
505
+ res . end ( ) ;
506
+ } ;
507
+
508
+ proxyServer = createServer ( 3000 , mw_proxy , '/api' ) ;
509
+ targetServer = createServer ( 8000 , mw_target ) ;
510
+
511
+ http . get ( 'http://localhost:3000/api/foo/bar' , function ( res ) {
512
+ res . on ( 'data' , function ( chunk ) {
513
+ responseBody = chunk . toString ( ) ;
514
+ done ( ) ;
515
+ } ) ;
516
+ } ) ;
517
+ } ) ;
518
+
519
+ afterEach ( function ( ) {
520
+ proxyServer . close ( ) ;
521
+ targetServer . close ( ) ;
522
+ } ) ;
523
+
524
+ it ( 'should proxy to target with the baseUrl' , function ( ) {
525
+ expect ( responseBody ) . to . equal ( '/api/foo/bar' ) ;
526
+ } ) ;
527
+
528
+ } ) ;
497
529
498
530
} ) ;
499
531
500
532
501
- function createServer ( portNumber , middleware ) {
533
+ function createServer ( portNumber , middleware , path ) {
502
534
var app = express ( ) ;
503
535
504
- if ( middleware ) {
536
+ if ( middleware , path ) {
537
+ console . log ( 'pathpathpathpathpathpathpath: ' , path ) ;
538
+ app . use ( path , middleware ) ;
539
+ }
540
+ else if ( middleware ) {
505
541
app . use ( middleware ) ;
506
542
}
507
543
0 commit comments