From b649fdff6bedc3f75dc759c42243f4377ac217ee Mon Sep 17 00:00:00 2001 From: Andres Reyes Hernandez Date: Sat, 3 Jan 2026 01:44:34 -0700 Subject: [PATCH] redireccion basica --- .gitignore | 19 ++++++- app/config/routes.php | 22 +++----- app/controllers/RedirectionController.php | 65 +++++++++++++++++++++++ app/middlewares/DetectMobileDevice.php | 26 +++++++++ 4 files changed, 117 insertions(+), 15 deletions(-) create mode 100644 app/controllers/RedirectionController.php create mode 100644 app/middlewares/DetectMobileDevice.php diff --git a/.gitignore b/.gitignore index b9dbda1..9fdcee0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,21 @@ vendor/ app/config/config.php composer.lock .vagrant/ -.runway-creds.json \ No newline at end of file +.runway-creds.json +.cursor/ +.gemini/ +.github/ +.windsurfrules +LICENSE +Vagrantfile +app/config/config_sample.php +app/log/ +docker-compose.yml +app/controllers/ApiExampleController.php +index-simple.php +runway +app/commands/SampleDatabaseCommand.php +app/views/welcome.php + + + diff --git a/app/config/routes.php b/app/config/routes.php index 1a5988b..432208f 100644 --- a/app/config/routes.php +++ b/app/config/routes.php @@ -1,12 +1,14 @@ group('', function(Router $router) use ($app) { $router->get('/', function() use ($app) { - $app->render('welcome', [ 'message' => 'You are gonna do great things!' ]); - }); + $app->redirect('https://google.com/maps'); + } ); - $router->get('/hello-world/@name', function($name) { - echo '

Hello world! Oh hey '.$name.'!

'; - }); + $router->get('/@path', [ RedirectionController::class, 'redirect' ] ); - $router->group('/api', function() use ($router) { - $router->get('/users', [ ApiExampleController::class, 'getUsers' ]); - $router->get('/users/@id:[0-9]', [ ApiExampleController::class, 'getUser' ]); - $router->post('/users/@id:[0-9]', [ ApiExampleController::class, 'updateUser' ]); - }); - -}, [ SecurityHeadersMiddleware::class ]); \ No newline at end of file +}, [ SecurityHeadersMiddleware::class, DetectMobileDevice::class ]); \ No newline at end of file diff --git a/app/controllers/RedirectionController.php b/app/controllers/RedirectionController.php new file mode 100644 index 0000000..a1a3d31 --- /dev/null +++ b/app/controllers/RedirectionController.php @@ -0,0 +1,65 @@ +app = $app; + } + + public function redirect( string $path) + { + $data = $this->getRedirections(); + $path_lower = strtolower($path); + + if (array_key_exists($path_lower, $data)) { + $data = $data[$path_lower]; + $website = $this->app->get('is_apple') ? $data['website1'] : $data['website2']; + + if (!empty($website)) { + $this->app->redirect($website); + return; + } + } + + //Fallback if path not found or website1 is empty + $this->app->redirect('https://google.com/maps'); + } + + public function getRedirections() { + + $data = [ + 'malecon' => [ + 'website1' => 'https://maps.apple/p/-ezVTdQ8aSUs.n', + 'website2' => 'https://maps.app.goo.gl/n1betgNTZgx4RoEJ8' + ], + 'puntacerritos' => [ + 'website1' => '', + 'website2' => 'https://maps.app.goo.gl/NSDoQZXnFWDcEgor5' + ], + 'zonadorada' => [ + 'website1' => '', + 'website2' => 'https://maps.app.goo.gl/CDt7vRw2M6oEqgBA8' + ], + 'galeron' => [ + 'website1' => '', + 'website2' => 'https://maps.app.goo.gl/CjkXvvNd2aA4ftiKA' + ], + 'monosbichis' => [ + 'website1' => '', + 'website2' => 'https://maps.app.goo.gl/M1dHZoRANfgCH9f67' + ], + 'pinchisplebes' => [ + 'website1' => '', + 'website2' => 'https://maps.app.goo.gl/o2uq6qQQiLxAkw7f6' + ] + ]; + + return $data; + } +} \ No newline at end of file diff --git a/app/middlewares/DetectMobileDevice.php b/app/middlewares/DetectMobileDevice.php new file mode 100644 index 0000000..16264d9 --- /dev/null +++ b/app/middlewares/DetectMobileDevice.php @@ -0,0 +1,26 @@ +app = $app; + } + + public function before(array $params): void + { + $userAgent = $this->app->request()->user_agent; + + $is_apple = preg_match('/iPhone|iPad|iPod/i', $userAgent); + + $this->app->set('is_apple', $is_apple); + } +} \ No newline at end of file