This commit is contained in:
William 2023-01-02 14:38:51 +00:00
parent d0db7231f0
commit 9ec14b6b73
3 changed files with 17 additions and 8 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);