@@ -466,8 +466,28 @@ class HttpTransport extends TransportAdapter {
466466 // errors alike. setHeader persists through later writeHead() calls.
467467 this . _applyCors ( req , res ) ;
468468
469+ let pathname ;
470+ try {
471+ pathname = new URL ( req . url || '/' , 'http://localhost' ) . pathname ;
472+ } catch {
473+ return _writeJson ( res , 400 , {
474+ ok : false ,
475+ error : 'invalid request URL' ,
476+ code : 'invalid_url' ,
477+ } ) ;
478+ }
479+
480+ if ( ! pathname . startsWith ( this . basePath + '/' ) ) {
481+ return _writeJson ( res , 404 , {
482+ ok : false ,
483+ error : `not a capability route: ${ pathname } ` ,
484+ code : 'not_found' ,
485+ } ) ;
486+ }
487+
469488 // Preflight: browsers send OPTIONS before a cross-origin POST with a
470- // JSON content-type. Answer it directly (no auth, no body).
489+ // JSON content-type. Answer it directly (no auth, no body) — but only
490+ // for capability routes, so unrelated paths still 404 above.
471491 if ( req . method === 'OPTIONS' && this . cors ) {
472492 res . writeHead ( 204 ) . end ( ) ;
473493 return ;
@@ -494,25 +514,6 @@ class HttpTransport extends TransportAdapter {
494514 }
495515 }
496516
497- let pathname ;
498- try {
499- pathname = new URL ( req . url || '/' , 'http://localhost' ) . pathname ;
500- } catch {
501- return _writeJson ( res , 400 , {
502- ok : false ,
503- error : 'invalid request URL' ,
504- code : 'invalid_url' ,
505- } ) ;
506- }
507-
508- if ( ! pathname . startsWith ( this . basePath + '/' ) ) {
509- return _writeJson ( res , 404 , {
510- ok : false ,
511- error : `not a capability route: ${ pathname } ` ,
512- code : 'not_found' ,
513- } ) ;
514- }
515-
516517 const tail = pathname . slice ( this . basePath . length + 1 ) ; // strip basePath + '/'
517518 // tail = "<kind>/<rest...>"; first segment is the kind, rest is the
518519 // ROS name (which itself can contain slashes).
@@ -716,18 +717,23 @@ function _normaliseBasePath(value) {
716717
717718/**
718719 * Normalise the `cors` option into either `false`, `true` (any origin),
719- * or a `Set<string>` of allowed origins.
720+ * or a `Set<string>` of allowed origins. A `"*"` value (or an array that
721+ * contains `"*"`) means "any origin" and is treated as `true`, matching
722+ * the CLI's `--http-cors *` shorthand.
720723 */
721724function _normaliseCors ( value ) {
722725 if ( value === undefined || value === null || value === false ) return false ;
723726 if ( value === true ) return true ;
724- if ( typeof value === 'string' ) return new Set ( [ value ] ) ;
727+ if ( typeof value === 'string' ) {
728+ return value === '*' ? true : new Set ( [ value ] ) ;
729+ }
725730 if ( Array . isArray ( value ) ) {
726731 if ( ! value . every ( ( v ) => typeof v === 'string' ) ) {
727732 throw new TypeError (
728733 'HttpTransport: cors array must contain only origin strings'
729734 ) ;
730735 }
736+ if ( value . includes ( '*' ) ) return true ;
731737 return new Set ( value ) ;
732738 }
733739 throw new TypeError (
0 commit comments