33var path = require ( 'path' ) ;
44var mime = require ( 'mime' ) ;
55var debug = require ( 'debug' ) ( 'serve-spm:express' ) ;
6+ var urlparse = require ( 'url' ) . parse ;
67
78var parse = require ( './parse' ) ;
89var util = require ( './util' ) ;
@@ -14,14 +15,18 @@ module.exports = function(root, opts) {
1415 var ignore = Array . isArray ( opts . ignore ) ? opts . ignore : [ ] ;
1516
1617 return function ( req , res , next ) {
17- next = req . headers [ 'servespmexit' ] ? notFound : ( next || notFound ) ;
18-
1918 if ( Array . isArray ( opts . paths ) ) {
2019 opts . paths . forEach ( function ( p ) {
2120 req . url = req . url . replace ( p [ 0 ] , p [ 1 ] ) ;
2221 } ) ;
2322 }
2423
24+ if ( opts . base ) {
25+ var basepath = urlparse ( opts . base ) . pathname ;
26+ basepath = basepath . replace ( / \/ $ / , '' ) ;
27+ req . url = req . url . replace ( basepath , '' ) ;
28+ }
29+
2530 debug ( 'parse url %s' , req . url ) ;
2631 var pkg = util . getPackage ( root ) ;
2732 var rootPkg = pkg ;
@@ -64,7 +69,8 @@ module.exports = function(root, opts) {
6469
6570 var opt = {
6671 pkg : pkg ,
67- ignore : ignore
72+ ignore : ignore ,
73+ base : opts . base
6874 } ;
6975 debug ( 'return transported file %s' , file . path ) ;
7076 transport ( file , opt , function ( err , file ) {
0 commit comments