diff options
author | Freya Murphy <freya@freyacat.org> | 2024-10-20 16:49:11 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-10-20 16:49:11 -0400 |
commit | cec4fb7ede7fee7b5621c096f3d5a4863b7b484e (patch) | |
tree | 9f0af211e9b2f9035220d94d07cd8edf381f61c1 /src/web/core | |
parent | update john (diff) | |
download | website-cec4fb7ede7fee7b5621c096f3d5a4863b7b484e.tar.gz website-cec4fb7ede7fee7b5621c096f3d5a4863b7b484e.tar.bz2 website-cec4fb7ede7fee7b5621c096f3d5a4863b7b484e.zip |
refactor config and add allowed_hosts
Diffstat (limited to 'src/web/core')
-rw-r--r-- | src/web/core/core.php | 12 | ||||
-rw-r--r-- | src/web/core/model.php | 9 | ||||
-rw-r--r-- | src/web/core/router.php | 4 |
3 files changed, 17 insertions, 8 deletions
diff --git a/src/web/core/core.php b/src/web/core/core.php index feaecdf..4c341c2 100644 --- a/src/web/core/core.php +++ b/src/web/core/core.php @@ -43,10 +43,16 @@ abstract class Core { $host = $_SERVER['HTTP_HOST']; - if (ENVIRONMENT == 'production') - $host = lang('domain'); + if (ENVIRONMENT == 'production') { + $default = CONFIG['domain']; + $allowed = CONFIG['allowed_hosts']; + if (!is_array($allowed)) + $allowed = [$allowed]; + if (!in_array($host, $allowed)) + $host = $default; + } - $base = lang('base_path'); + $base = CONFIG['base_path']; $url = "{$scheme}://{$host}{$base}{$path}"; if ($timestamp) { $time = Core::asset_stamp($path); diff --git a/src/web/core/model.php b/src/web/core/model.php index c57fd5c..6a42a98 100644 --- a/src/web/core/model.php +++ b/src/web/core/model.php @@ -2,7 +2,10 @@ abstract class Model extends Component { - public static function get_base_data(?string $app = NULL): array + /** + * @return array<string,mixed> + */ + public static function get_base_data(?string $app = NULL): array { $data = array(); $data['title'] = lang('first_name'); @@ -10,8 +13,8 @@ abstract class Model extends Component { $data['css'] = array(); $data['js'] = array(); - $style = $GLOBALS['style']; - $js = $GLOBALS['js']; + $style = CONFIG['style']; + $js = CONFIG['js']; if (!$app) $app = CONTEXT['app']; diff --git a/src/web/core/router.php b/src/web/core/router.php index 2cda384..a1307cf 100644 --- a/src/web/core/router.php +++ b/src/web/core/router.php @@ -30,7 +30,8 @@ class Router extends Component { $path = substr($path, 1); // get modified route - foreach ($GLOBALS['routes'] as $key => $value) { + $routes = CONFIG['routes']; + foreach ($routes as $key => $value) { $key = "/^{$key}$/"; if (!preg_match($key, $path, $matches)) continue; @@ -83,7 +84,6 @@ class Router extends Component { 'args' => array_slice($parts, 2), ); - $routes = $GLOBALS['routes']; if (isset($routes[$path])) { $parts = explode('/', $routes[$path]); if (count($parts) == 1) { |