File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env node
22require ( 'dotenv' ) . config ( ) ;
3- const config = require ( 'camelspace' ) ( 'upwardJs' ) ( process . env ) ;
3+ const config = require ( 'camelspace' ) ( 'upwardJs' ) . fromEnv ( process . env ) ;
44
55require ( '../lib/createUpwardServer.js' ) ( config ) . catch ( e => {
66 console . error ( e . stack ) ;
Original file line number Diff line number Diff line change @@ -41,10 +41,34 @@ class DirectoryResolver extends AbstractResolver {
4141 this . visitor . upwardPath ,
4242 staticOpts
4343 ) ;
44- server = serveStatic (
45- path . resolve ( path . dirname ( this . visitor . upwardPath ) , directory ) ,
46- staticOpts
44+
45+ const baseDir = path . resolve (
46+ path . dirname ( this . visitor . upwardPath ) ,
47+ directory
4748 ) ;
49+ server = ( req , res , next ) => {
50+ const baseDirSegments = baseDir
51+ . split ( path . sep )
52+ . filter ( segment => segment ) ;
53+ const lastBaseSegment =
54+ baseDirSegments [ baseDirSegments . length - 1 ] ;
55+
56+ if (
57+ lastBaseSegment &&
58+ req . url . startsWith ( `/${ lastBaseSegment } /` )
59+ ) {
60+ req . url = req . url . substring ( `/${ lastBaseSegment } ` . length ) ;
61+ debug (
62+ `Removed redundant path segment "${ lastBaseSegment } " from request URL: ${
63+ req . url
64+ } `
65+ ) ;
66+ }
67+
68+ const staticMiddleware = serveStatic ( baseDir , staticOpts ) ;
69+ staticMiddleware ( req , res , next ) ;
70+ } ;
71+
4872 DirectoryResolver . servers . set ( directory , server ) ;
4973 }
5074
You can’t perform that action at this time.
0 commit comments