From 5f0a02682c0220390ff3200a3fe7078d27d44768 Mon Sep 17 00:00:00 2001 From: Christian Hartmann Date: Tue, 15 Oct 2024 18:05:33 +0200 Subject: [PATCH] move CORS preflight to ApiController Signed-off-by: Christian Hartmann --- appinfo/routes.php | 38 -------------------------------- lib/Controller/ApiController.php | 9 ++++++++ 2 files changed, 9 insertions(+), 38 deletions(-) delete mode 100644 appinfo/routes.php diff --git a/appinfo/routes.php b/appinfo/routes.php deleted file mode 100644 index 504261edd..000000000 --- a/appinfo/routes.php +++ /dev/null @@ -1,38 +0,0 @@ - - * - * @author affan98 - * @author Christian Hartmann - * @author Ferdinand Thiessen - * @author John Molakvoæ (skjnldsv) - * @author Jonas Rittershofer - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -use OCA\Forms\Constants; - -return [ - 'ocs' => [ - // CORS Preflight - ['name' => 'api#preflightedCors', 'url' => Constants::API_BASE . '{path}', 'verb' => 'OPTIONS', 'requirements' => [ - 'path' => '.+', - 'apiVersion' => 'v3' - ]], - ] -]; diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 9b5ae374c..49cf1d241 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -100,6 +100,15 @@ public function __construct( $this->currentUser = $userSession->getUser(); } + // CORS preflight + /** + * Handle CORS options request by calling parent function + */ + #[ApiRoute(verb: 'OPTIONS', url: Constants::API_BASE . '{path}', requirements: ['path' => '.+', 'apiVersion' => 'v3'])] + public function preflightedCors() { + parent::preflightedCors(); + } + // API v3 methods // Forms /**