@@ -73,28 +73,45 @@ private static string[] GetAcceptHeaders(HttpRequest contextRequest)
7373 ? header . MediaType
7474 : null ) ;
7575
76- private MidFunc SqlStreamStreamBrowserJavascript => ( context , next )
77- => context . Request . Path . Value ? . EndsWith ( ".js" ) ?? false
78- ? ForwardToClientDevServer (
76+ private MidFunc SqlStreamStreamBrowserJavascript => ( context , next ) =>
77+ {
78+ if ( context . Request . Path . Value ? . EndsWith ( ".js" ) ?? false )
79+ {
80+ var segments = context . Request . Path . ToUriComponent ( ) . Split ( '/' ) ;
81+ if ( segments . Length > 2 )
82+ {
83+ return RedirectToPathBase ( context , $ "/{ segments . Last ( ) } ") ;
84+ }
85+
86+ return ForwardToClientDevServer (
7987 context ,
80- $ "{ context . Request . PathBase . ToUriComponent ( ) } { context . Request . Path . ToUriComponent ( ) } ")
81- : next ( ) ;
88+ context . Request . PathBase + context . Request . Path ) ;
89+ }
90+ return next ( ) ;
91+ } ;
8292
8393 private MidFunc SqlStreamStreamBrowserHtml => ( context , next )
8494 => GetAcceptHeaders ( context . Request )
8595 . Any ( header => header == "text/html" )
8696 ? ForwardToClientDevServer ( context , context . Request . PathBase . ToUriComponent ( ) )
8797 : next ( ) ;
8898
89- private async Task ForwardToClientDevServer ( HttpContext context , string path )
99+ private Task RedirectToPathBase ( HttpContext context , PathString path )
100+ {
101+ context . Response . Redirect ( context . Request . PathBase + path ) ;
102+
103+ return Task . CompletedTask ;
104+ }
105+
106+ private async Task ForwardToClientDevServer ( HttpContext context , PathString path )
90107 {
91108 using ( var request = new HttpRequestMessage (
92109 new HttpMethod ( context . Request . Method ) ,
93110 new UriBuilder
94111 {
95112 Port = 3000 ,
96113 Host = "localhost" ,
97- Path = path ,
114+ Path = path . ToUriComponent ( ) ,
98115 Query = context . Request . QueryString . ToUriComponent ( )
99116 } . Uri ) )
100117 using ( var response = await _httpClient . SendAsync ( request ) )
0 commit comments