File tree Expand file tree Collapse file tree
packages/cli-server-api/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,17 @@ import {json} from 'body-parser';
1111import connect from 'connect' ;
1212import open from 'open' ;
1313
14+ // Cache the imported sanitizeUrl function to avoid repeated dynamic imports
15+ let sanitizeUrlFn : ( ( url : string ) => string ) | null = null ;
16+
17+ async function getSanitizeUrl ( ) : Promise < ( url : string ) => string > {
18+ if ( sanitizeUrlFn === null ) {
19+ const module = await import ( 'strict-url-sanitise' ) ;
20+ sanitizeUrlFn = module . sanitizeUrl ;
21+ }
22+ return sanitizeUrlFn ;
23+ }
24+
1425/**
1526 * Open a URL in the system browser.
1627 */
@@ -39,7 +50,7 @@ export async function openURLMiddleware(
3950
4051 let sanitizedUrl : string ;
4152 try {
42- const { sanitizeUrl} = await import ( 'strict-url-sanitise' ) ;
53+ const sanitizeUrl = await getSanitizeUrl ( ) ;
4354 sanitizedUrl = sanitizeUrl ( url ) ;
4455 } catch ( error ) {
4556 res . writeHead ( 400 ) ;
You can’t perform that action at this time.
0 commit comments