1
1
mirror of https://github.com/neosubhamoy/neosubhamoy-portfolio.git synced 2025-12-19 20:33:06 +05:30

(refactor): changed router file path (feat): added global host config

This commit is contained in:
2023-11-09 21:45:15 +05:30
parent c21d06a64d
commit 18753f116b
8 changed files with 16 additions and 2 deletions

View File

@@ -0,0 +1,10 @@
<?php
$currentHost = $_SERVER['HTTP_HOST'];
if($currentHost == "localhost") {
$basePath = "https://localhost/neosubhamoy/htdocs";
}
else {
$basePath = "https://" + $host;
}
?>

43
htdocs/core/router.php Normal file
View File

@@ -0,0 +1,43 @@
<?php
$host = $_SERVER['HTTP_HOST'];
$uri = parse_url($_SERVER['REQUEST_URI'])['path'];
$serverRoutes = [
'/' => 'home.php',
'/projects' => 'projects.php',
'/blog' => 'blog.php',
'/contact' => 'contact.php',
];
$devRoutes = [
'/neosubhamoy/htdocs/' => 'home.php',
'/neosubhamoy/htdocs/projects' => 'projects.php',
'/neosubhamoy/htdocs/blog' => 'blog.php',
'/neosubhamoy/htdocs/contact' => 'contact.php',
];
if ($host == "localhost") {
$routes = $devRoutes;
}
else {
$routes = $serverRoutes;
}
function routeTraffictToPages($uri, $routes) {
if(array_key_exists($uri, $routes)) {
require $routes[$uri];
}
else {
error_page(404);
}
}
function error_page($status_code) {
http_response_code($status_code);
require "error/{$status_code}.php";
die();
}
routeTraffictToPages($uri, $routes);
?>