@@ -612,20 +612,56 @@ public function testWildcardRoute(): void
612612 $ _SERVER ['REQUEST_METHOD ' ] = 'GET ' ;
613613 $ _SERVER ['REQUEST_URI ' ] = '/unknown_path ' ;
614614
615+ App::init ()
616+ ->action (function () {
617+ $ route = $ this ->app ->getRoute ();
618+ App::setResource ('myRoute ' , fn () => $ route );
619+ });
620+
621+ App::options ()
622+ ->inject ('request ' )
623+ ->inject ('response ' )
624+ ->action (function (Request $ request , Response $ response ) {
625+ $ origin = $ request ->getOrigin ();
626+ $ response
627+ ->addHeader ('Server ' , 'Appwrite ' )
628+ ->addHeader ('Access-Control-Allow-Methods ' , 'GET, POST, PUT, PATCH, DELETE ' )
629+ ->addHeader ('Access-Control-Allow-Headers ' , 'Origin, Cookie, Set-Cookie, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-Appwrite-Mode, X-Appwrite-JWT, X-Appwrite-Response-Format, X-SDK-Version, X-SDK-Name, X-SDK-Language, X-SDK-Platform, X-Appwrite-ID, Content-Range, Range, Cache-Control, Expires, Pragma, X-Fallback-Cookies ' )
630+ ->addHeader ('Access-Control-Expose-Headers ' , 'X-Fallback-Cookies ' )
631+ ->addHeader ('Access-Control-Allow-Origin ' , $ origin )
632+ ->addHeader ('Access-Control-Allow-Credentials ' , 'true ' )
633+ ->noContent ();
634+ });
635+
615636 App::wildcard ()
637+ ->inject ('myRoute ' )
616638 ->inject ('response ' )
617- ->action (function ($ response ) {
618- $ response ->send ('HELLO ' );
639+ ->action (function (mixed $ myRoute , $ response ) {
640+ if ($ myRoute == null ) {
641+ $ response ->send ('ROUTE IS NULL! ' );
642+ } else {
643+ $ response ->send ('HELLO ' );
644+ }
619645 });
620646
621647 \ob_start ();
622648 @$ this ->app ->run (new Request (), new Response ());
623649 $ result = \ob_get_contents ();
624650 \ob_end_clean ();
625651
652+ $ this ->assertEquals ('HELLO ' , $ result );
653+
654+ \ob_start ();
655+ $ req = new Request ();
656+ $ req = $ req ->setMethod ('OPTIONS ' );
657+ @$ this ->app ->run ($ req , new Response ());
658+ $ result = \ob_get_contents ();
659+ \ob_end_clean ();
660+
661+ $ this ->assertEquals ('' , $ result );
662+
626663 $ _SERVER ['REQUEST_METHOD ' ] = $ method ;
627664 $ _SERVER ['REQUEST_URI ' ] = $ uri ;
628665
629- $ this ->assertEquals ('HELLO ' , $ result );
630666 }
631667}
0 commit comments