mirror of
https://github.com/mivodev/mivo.git
synced 2026-01-26 13:31:56 +07:00
Chore: Bump version to v1.1.0 and implement automated release system
This commit is contained in:
41
app/Middleware/RouterCheckMiddleware.php
Normal file
41
app/Middleware/RouterCheckMiddleware.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Models\Config;
|
||||
|
||||
class RouterCheckMiddleware implements MiddlewareInterface {
|
||||
public function handle($request, \Closure $next) {
|
||||
// We need to extract the session from the URI
|
||||
// Pattern: /{session}/...
|
||||
|
||||
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
$scriptName = dirname($_SERVER['SCRIPT_NAME']);
|
||||
if (strpos($path, $scriptName) === 0) {
|
||||
$path = substr($path, strlen($scriptName));
|
||||
}
|
||||
$path = '/' . trim($path, '/');
|
||||
|
||||
// Regex to grab first segment
|
||||
if (preg_match('#^/([^/]+)#', $path, $matches)) {
|
||||
$session = $matches[1];
|
||||
|
||||
// Exclude system routes that might mimic this pattern if any (like 'settings')
|
||||
// But 'settings' is usually top level.
|
||||
// If the user name their router "settings", it would conflict anyway.
|
||||
// Let's assume standard routing structure.
|
||||
|
||||
if ($session === 'login' || $session === 'logout' || $session === 'settings' || $session === 'install' || $session === 'api') {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$configModel = new Config();
|
||||
if ($session !== 'demo' && !$configModel->getSession($session)) {
|
||||
// Router NOT FOUND
|
||||
\App\Helpers\ErrorHelper::show(404, 'errors.router_not_found_title', 'errors.router_not_found_desc');
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user