From 4ceea3b76d710b68df9edb13d345e59edabf9a95 Mon Sep 17 00:00:00 2001 From: iazaran Date: Mon, 17 Jan 2022 00:56:49 +0400 Subject: [PATCH 1/8] Nginx conf updated --- docker/{nginx => nginx_http1}/default.conf | 8 +++----- docker/nginx_http2/default.conf | 11 +++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) rename docker/{nginx => nginx_http1}/default.conf (73%) create mode 100644 docker/nginx_http2/default.conf diff --git a/docker/nginx/default.conf b/docker/nginx_http1/default.conf similarity index 73% rename from docker/nginx/default.conf rename to docker/nginx_http1/default.conf index 8fdfff4..3ee78e8 100644 --- a/docker/nginx/default.conf +++ b/docker/nginx_http1/default.conf @@ -1,13 +1,12 @@ server { listen 80; client_max_body_size 108M; - access_log /var/log/nginx/application.access.log; + access_log /var/log/nginx/app.access.log; + error_log /var/log/nginx/app.error.log; index index.php; - error_log /var/log/nginx/error.log; - access_log /var/log/nginx/access.log; root /var/www/public; - # try to serve file directly, fallback to index.php + # Try to serve file directly, fallback to index.php location / { try_files $uri /index.php$is_args$args; gzip_static on; @@ -21,5 +20,4 @@ server { fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log"; fastcgi_param PATH_INFO $fastcgi_path_info; } - } diff --git a/docker/nginx_http2/default.conf b/docker/nginx_http2/default.conf new file mode 100644 index 0000000..823e383 --- /dev/null +++ b/docker/nginx_http2/default.conf @@ -0,0 +1,11 @@ +server { + listen 80 http2; + client_max_body_size 108M; + access_log /var/log/nginx/grpc.access.log; + error_log /var/log/nginx/grpc.error.log; + + # Listening for unencrypted gRPC traffic on port 80 and forwarding requests to the server on port 50051 + location / { + grpc_pass grpc://localhost:50051; + } +} From 7a6d017bd73afeeff61c797bdf2e644bd40616b2 Mon Sep 17 00:00:00 2001 From: iazaran Date: Mon, 17 Jan 2022 00:57:32 +0400 Subject: [PATCH 2/8] Image uploading bug fixed --- src/App/HandleForm.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/App/HandleForm.php b/src/App/HandleForm.php index f3a6ab0..0f3903d 100644 --- a/src/App/HandleForm.php +++ b/src/App/HandleForm.php @@ -186,10 +186,12 @@ public static function upload( } imagecopyresampled($newImage, $oldImage, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); - $target2 = $target1 . $baseName . '.' . $fileExtension; - imagejpeg($newImage, $target2, 100); - $overlayImage = imagecreatefrompng($overlay); - imagecopyresampled($newImage, $overlayImage, 0, 0, 0, 0, $overlayWidth, $overlayHeight, $overlayWidth, $overlayHeight); + $target2 = $target . $baseName . '.' . $fileExtension; + if (!empty($overlay)) { + imagejpeg($newImage, $target2, 100); + $overlayImage = imagecreatefrompng($overlay); + imagecopyresampled($newImage, $overlayImage, 0, 0, 0, 0, $overlayWidth, $overlayHeight, $overlayWidth, $overlayHeight); + } imagejpeg($newImage, $target2, $compressRate); unlink($target1); From 5783b92b29afae9a7cc1ea5ef4b8745d8e0c3f95 Mon Sep 17 00:00:00 2001 From: iazaran Date: Mon, 17 Jan 2022 00:58:18 +0400 Subject: [PATCH 3/8] Auth bug fixed --- src/Models/Auth.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Models/Auth.php b/src/Models/Auth.php index 0cbad6d..90f484d 100644 --- a/src/Models/Auth.php +++ b/src/Models/Auth.php @@ -52,7 +52,6 @@ public static function verify(object $request): bool !is_null(Database::fetch()) && !is_null(Database::fetch()['user_token']) && $request->user_token == Database::fetch()['user_token'] - && setcookie('loggedin', base64_encode($request->email), time() + (86400 * COOKIE_DAYS)) ) { Database::query("UPDATE users SET verified = :verified WHERE email = :email"); Database::bind([ @@ -60,7 +59,10 @@ public static function verify(object $request): bool ':email' => $request->email, ]); - if (Database::execute()) return true; + if (Database::execute()) { + setcookie('loggedin', base64_encode($request->email), time() + (86400 * COOKIE_DAYS)); + return true; + } } return false; } @@ -111,8 +113,10 @@ public static function login(object $request): bool && password_verify($request->password, Database::fetch()['password']) && !is_null(Database::fetch()['user_token']) && Database::fetch()['verified'] - && setcookie('loggedin', base64_encode($request->email), time() + (86400 * COOKIE_DAYS)) - ) return true; + ) { + setcookie('loggedin', base64_encode($request->email), time() + (86400 * COOKIE_DAYS)); + return true; + } return false; } From d773072c61d1751e3571f1b09126ed65f72be9ec Mon Sep 17 00:00:00 2001 From: iazaran Date: Mon, 17 Jan 2022 00:58:35 +0400 Subject: [PATCH 4/8] gRPC codes updated --- src/Controllers/API/BlogGrpcController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controllers/API/BlogGrpcController.php b/src/Controllers/API/BlogGrpcController.php index 7381e7c..00405f2 100644 --- a/src/Controllers/API/BlogGrpcController.php +++ b/src/Controllers/API/BlogGrpcController.php @@ -35,7 +35,7 @@ class BlogGrpcController implements BlogInterface * * @param string $host */ - public function __construct(string $host) + public function __construct(string $host = 'localhost:50051') { $this->client = new BlogClient($host, ['credentials' => ChannelCredentials::createDefault()]); } From bca97a86254a8057c84a5e8bd94c2c2169f9cda6 Mon Sep 17 00:00:00 2001 From: iazaran Date: Mon, 17 Jan 2022 00:58:47 +0400 Subject: [PATCH 5/8] Routes updated --- src/grpc_route.php | 6 ++++++ src/routes.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 src/grpc_route.php diff --git a/src/grpc_route.php b/src/grpc_route.php new file mode 100644 index 0000000..58c95b0 --- /dev/null +++ b/src/grpc_route.php @@ -0,0 +1,6 @@ +addHttp2Port('localhost:50051'); +$server->handle(new \Controllers\API\BlogGrpcController()); +$server->run(); diff --git a/src/routes.php b/src/routes.php index d94afd2..865a571 100644 --- a/src/routes.php +++ b/src/routes.php @@ -22,7 +22,7 @@ Router::get('/logout', 'AuthController@logout'); /** - * API routes + * RESTful API routes */ Router::get('/api/blog', 'API\BlogController@index'); Router::get('/api/blog/(:any)', 'API\BlogController@show'); From cbd86322f8ca0f631d51a21ba162f9b70c3f7eb3 Mon Sep 17 00:00:00 2001 From: iazaran Date: Mon, 17 Jan 2022 00:58:57 +0400 Subject: [PATCH 6/8] Composer updated --- composer.json | 3 ++- composer.lock | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index b4c747e..63ea995 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "files": [ "env.php", "src/migrations.php", - "src/routes.php" + "src/routes.php", + "src/grpc_route.php" ], "classmap": [ "src/" diff --git a/composer.lock b/composer.lock index 43841dd..3a484dd 100644 --- a/composer.lock +++ b/composer.lock @@ -193,5 +193,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.0.0" } From ea34b518fccfe4bf51955a3c6f04f3c584194abf Mon Sep 17 00:00:00 2001 From: iazaran Date: Mon, 17 Jan 2022 00:59:14 +0400 Subject: [PATCH 7/8] Docker compose services updated --- docker-compose.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a25cc49..d469432 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,17 +1,28 @@ version: '3.1' services: - php-mvc-server: + php-mvc-app-server: image: nginx:alpine - container_name: php-mvc-server + container_name: php-mvc-app-server volumes: - ./:/var/www - - ./docker/nginx:/etc/nginx/conf.d/ + - ./docker/nginx_http1:/etc/nginx/conf.d/ ports: - '8080:80' networks: - php-mvc-network + php-mvc-grpc-server: + image: nginx:alpine + container_name: php-mvc-grpc-server + volumes: + - ./:/var/www + - ./docker/nginx_http2:/etc/nginx/conf.d/ + ports: + - '8585:80' + networks: + - php-mvc-network + php-mvc-app: build: context: . From c8abe4057413d83e4f76140bac5d6beb937e1118 Mon Sep 17 00:00:00 2001 From: iazaran Date: Mon, 17 Jan 2022 00:59:25 +0400 Subject: [PATCH 8/8] README.md updated --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f10dc45..925d9e8 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ > This project tries to cover some PHP features in a simple MVC structure with minimum installed composer packages. Then developers can use packages for specific requirements. Please add your ideas in Discussions, ask features or report bugs in issues. -🚧 WIP: gRPC server _(gRPC client not completed yet, and gRPC server is under working, so be careful about the bugs in gRPC)_ +🚧 WIP: gRPC server _(gRPC client not completed yet, and gRPC server is under working, so be careful about the bugs in gRPC ⚠)_ 💡 TODO: WebSocket