Flatten structure to better match current PHP practice.

This commit is contained in:
Greg Sarjeant 2025-06-02 08:21:35 -04:00
parent 51595c13eb
commit f9aa2c7cb7
15 changed files with 16 additions and 20 deletions

View File

@ -19,7 +19,7 @@ server {
# PHP routing - everything under /tkr goes through index.php
location /tkr {
alias /var/www/html/public;
alias /var/www/html/tkr/public;
index index.php;
# Cache static files
@ -37,7 +37,7 @@ server {
# so bots and scanners can't tell this is a php app
location = /tkr/index.php {
fastcgi_pass php:9000;
fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/tkr/public/index.php;
include fastcgi_params;
# Additional FastCGI params
@ -60,7 +60,7 @@ server {
# Fallback for /tkr routing - all non-file requests go to index.php
location @tkr_fallback {
fastcgi_pass php:9000;
fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/tkr/public/index.php;
include fastcgi_params;
# Additional FastCGI params

View File

@ -5,7 +5,7 @@ services:
ports:
- "80:80"
volumes:
- ./src:/var/www/html
- ./public:/var/www/html/tkr/public
- ./configs/nginx/folder.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
@ -15,11 +15,14 @@ services:
image: php:8.2-fpm-alpine
container_name: php-fpm
volumes:
- ./src:/var/www/html
- ./public:/var/www/html/tkr/public
- ./src:/var/www/html/tkr/src
- ./storage:/var/www/html/tkr/storage
- ./templates:/var/www/html/tkr/templates
command: >
sh -c "
chown -R www-data:www-data /var/www/html/storage &&
chmod -R 775 /var/www/html/storage &&
chown -R www-data:www-data /var/www/html/tkr/storage &&
chmod -R 775 /var/www/html/tkr/storage &&
php-fpm
"
restart: unless-stopped

View File

@ -3,8 +3,8 @@
define('APP_ROOT', dirname(dirname(__FILE__)));
define('CLASSES_DIR', APP_ROOT . '/classes');
define('LIB_DIR', APP_ROOT . '/lib');
define('CLASSES_DIR', APP_ROOT . '/src/classes');
define('LIB_DIR', APP_ROOT . '/src/lib');
define('STORAGE_DIR', APP_ROOT . '/storage');
define('TEMPLATES_DIR', APP_ROOT . '/templates');
@ -29,15 +29,9 @@ $isLoggedIn = isset($_SESSION['user_id']);
$config = Config::load();
$user = User::load();
// Define your base path (subdirectory)
#$basePath = '/tkr';
// Get HTTP data
// Get request data
$method = $_SERVER['REQUEST_METHOD'];
$request = $_SERVER['REQUEST_URI'];
// Remove the base path from the URL
// and strip the trailing slash from the resulting route
$path = parse_url($request, PHP_URL_PATH);
// return a 404 if s request for a .php file gets this far.
@ -47,6 +41,8 @@ if (preg_match('/\.php$/', $path)) {
exit;
}
// Remove the base path from the URL
// and strip the trailing slash from the resulting route
if (strpos($path, $config->basePath) === 0) {
$path = substr($path, strlen($config->basePath));
}
@ -77,10 +73,8 @@ function route($pattern, $callback, $methods = ['GET']) {
header('Content-Type: text/html; charset=utf-8');
echo "Path: " . $path;
// Define your routes
// routes
route('', function() use ($isLoggedIn, $config, $user) {
#include TEMPLATES_DIR . "/home.php";
#echo render_home_page($isLoggedIn, $config, $user);
$page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1;
$limit = $config->itemsPerPage;
$offset = ($page - 1) * $limit;
@ -95,4 +89,3 @@ route('', function() use ($isLoggedIn, $config, $user) {
echo render_template(TEMPLATES_DIR . "/home.php", $vars);
});
//isset($_SESSION['user_id'])