File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
packages/cli/plugin-data-loader/src/runtime Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,18 @@ function convertModernRedirectResponse(headers: Headers, basename: string) {
5252 } ) ;
5353}
5454
55+ export function hasFileExtension ( pathname : string ) : boolean {
56+ const lastSegment = pathname . split ( '/' ) . pop ( ) || '' ;
57+ const dotIndex = lastSegment . lastIndexOf ( '.' ) ;
58+
59+ if ( dotIndex === - 1 ) {
60+ return false ;
61+ }
62+
63+ const extension = lastSegment . substring ( dotIndex ) . toLowerCase ( ) ;
64+ return extension !== '.html' ;
65+ }
66+
5567export const handleRequest : ServerLoaderBundle [ 'handleRequest' ] = async ( {
5668 request,
5769 serverRoutes,
@@ -61,6 +73,13 @@ export const handleRequest: ServerLoaderBundle['handleRequest'] = async ({
6173} ) : Promise < Response | void > => {
6274 const url = new URL ( request . url ) ;
6375 const routeId = url . searchParams . get ( LOADER_ID_PARAM ) as string ;
76+
77+ // Check if pathname has file extension (excluding .html)
78+ // Reject requests like /three/user/profile.js but allow /three/user/profile
79+ if ( hasFileExtension ( url . pathname ) ) {
80+ return ;
81+ }
82+
6483 const entry = matchEntry ( url . pathname , serverRoutes ) ;
6584 // LOADER_ID_PARAM is the indicator for CSR data loader request.
6685 if ( ! routeId || ! entry ) {
You can’t perform that action at this time.
0 commit comments