diff --git a/Dockerfile b/Dockerfile index c7785d0..ad27b32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,13 @@ FROM docker.io/alpine:latest -RUN apk update && apk add nginx php-fpm - -RUN adduser -D -g 'www' www - -RUN mkdir /www && \ +RUN apk update && apk add nginx php-fpm && \ + adduser -D -g 'www' www && \ + mkdir /www && \ chown -R www:www /var/lib/nginx && \ chown -R www:www /www COPY ./docker/nginx.conf /etc/nginx/nginx.conf - COPY ./ /www - COPY ./docker/run.sh /opt/run.sh RUN chmod +x /opt/run.sh diff --git a/app/WillySoft/Http/Route.php b/app/WillySoft/Http/Route.php index df10abc..b993d8b 100644 --- a/app/WillySoft/Http/Route.php +++ b/app/WillySoft/Http/Route.php @@ -18,8 +18,17 @@ abstract class Route // check if the route matches and add parameters if any $args = []; + $request_path = (function() { + $haystack = strtok($_SERVER["REQUEST_URI"], '?'); + $needle = dirname($_SERVER['SCRIPT_NAME']); + if ($needle === '/') { + $needle = ''; + } + $pos = strpos($haystack, $needle); + return substr_replace($haystack, '', $pos, strlen($needle)); + })(); $path_parts = explode('/', $path); - $request_path_parts = explode('/', strtok($_SERVER["REQUEST_URI"], '?')); + $request_path_parts = explode('/', $request_path); for ($i=0; $i < count($path_parts); $i++) { if (empty($path_parts[$i])) { continue; diff --git a/routes/start.php b/routes/start.php index 6a295d9..4e29f8e 100644 --- a/routes/start.php +++ b/routes/start.php @@ -9,6 +9,10 @@ ErrorHandler::register(function($error_messages) { Route::get('/', fn() => view('pages/home')); Route::get('/matrix', fn() => view('pages/matrix')); +Route::get('/test/$whatever?', function($whatever = 'Default Value') { + echo htmlspecialchars($whatever); +}); +Route::get('/error', fn() => 1 / 0); // since no route was matched we show a page not found error http_response_code(404);