@@ -494,14 +494,50 @@ describe('http-proxy-middleware in actual server', function () {
494494 } ) ;
495495 } ) ;
496496
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+ } ) ;
497529
498530} ) ;
499531
500532
501- function createServer ( portNumber , middleware ) {
533+ function createServer ( portNumber , middleware , path ) {
502534 var app = express ( ) ;
503535
504- if ( middleware ) {
536+ if ( middleware , path ) {
537+ console . log ( 'pathpathpathpathpathpathpath: ' , path ) ;
538+ app . use ( path , middleware ) ;
539+ }
540+ else if ( middleware ) {
505541 app . use ( middleware ) ;
506542 }
507543
0 commit comments