diff --git a/README.md b/README.md index 6570c1c..30090ac 100644 --- a/README.md +++ b/README.md @@ -26,25 +26,48 @@ You can configure your frontend using some environment variables described below | Variable | Description | Default | |-------------------------|-------------------------------------------------------------|---------------------------| -| `FRONTIER_TYPE` | Define type of controller `http` or `view` | `view` | +| `FRONTIER_TYPE` | Define type of controller `http`, `proxy` or `view` | `view` | | `FRONTIER_ENDPOINT` | Endpoint where the frontend will run | `frontier` | | `FRONTIER_VIEW` | Default `view` that will be rendered or `url` of the server | `frontier::index` | | `FRONTIER_VIEWS_PATH` | Directory where all the `views` are | `frontier/resources/html` | | `FRONTIER_FIND` | Content that will be replaced | | | `FRONTIER_REPLACE_WITH` | Content that will be the replacement | | +| `FRONTIER_PROXY` | URIs that you will do proxy | | +| `FRONTIER_CACHE` | When `http` type, indicates se cache will be do | `true` | ### Frontend types -You can use 2 different types of frontend `http` or `view`. +You can use 3 different types of frontend `http`, `proxy` or `view`. #### HTTP -Use in `FRONTIER_VIEW` the URL of your frontend server, if you use Vite is `http://localhost:5173`. +Use in `FRONTIER_VIEW` the URL of your frontend server. + +#### Proxy + +Use in `FRONTIER_VIEW` the URL of your real server. #### View Use in `FRONTIER_VIEW` the name of your view that you initialize your frontend, this is relative a Blade views. +### Examples + +#### Vite and Vue.js + +When using [Vite](https://vitejs.dev/) and [Vue.js](https://vuejs.org/) you can start your project with these +environment variables. + +```bash +FRONTIER_ENDPOINT=/vue +FRONTIER_TYPE=http +FRONTIER_VIEW=http://localhost:5173/ +FRONTIER_FIND=/@vite/client,/src/main.ts,/vite.svg +FRONTIER_REPLACE_WITH=http://localhost:5173/@vite/client,http://localhost:5173/src/main.ts,http://localhost:5173/vite.svg +FRONTIER_PROXY=/vite.svg +FRONTIER_CACHE=false +``` + ### Multiple frontends You can run multiple frontends, just create a custom configuration file. @@ -53,7 +76,7 @@ You can run multiple frontends, just create a custom configuration file. php artisan vendor:publish --tag=frontier ``` -The `config/frontier.php` file will be created in your Laravel app. This file contains some settings that can be +The `config/frontier.php` file will be created in your Laravel app. This file contains some settings that can be replicated to add more frontends to your app. ## License diff --git a/composer.json b/composer.json index 98b3c87..e767cf0 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,17 @@ "role": "Developer" } ], + "require": { + "guzzlehttp/guzzle": "^7", + "illuminate/http": "^8|^9|^10", + "illuminate/support": "^8|^9|^10", + "illuminate/view": "^8|^9|^10" + }, + "require-dev": { + "laravel/pint": "^1.10", + "orchestra/testbench": "^8.5", + "pestphp/pest": "^2.6" + }, "autoload": { "psr-4": { "Dex\\Laravel\\Frontier\\": "src/" @@ -21,25 +32,6 @@ "Dex\\Laravel\\Frontier\\Tests\\": "tests/" } }, - "scripts": { - "coverage": "XDEBUG_MODE=coverage vendor/bin/pest --coverage", - "format": "vendor/bin/pint", - "test": "vendor/bin/pest" - }, - "scripts-descriptions": { - "coverage": "Run code coverage", - "format": "Format code", - "test": "Run tests" - }, - "require": { - "illuminate/support": "^8|^9|^10" - }, - "require-dev": { - "orchestra/testbench": "^8.5", - "guzzlehttp/guzzle": "^7.4", - "laravel/pint": "^1.10", - "pestphp/pest": "^2.6" - }, "extra": { "laravel": { "providers": [ @@ -50,6 +42,17 @@ "config": { "allow-plugins": { "pestphp/pest-plugin": true - } + }, + "sort-packages": true + }, + "scripts": { + "coverage": "XDEBUG_MODE=coverage vendor/bin/pest --coverage", + "format": "vendor/bin/pint", + "test": "vendor/bin/pest" + }, + "scripts-descriptions": { + "coverage": "Run code coverage", + "format": "Format code", + "test": "Run tests" } } diff --git a/tests/FrontendHttpControllerTest.php b/tests/FrontendHttpControllerTest.php index 02f015b..f57c89e 100644 --- a/tests/FrontendHttpControllerTest.php +++ b/tests/FrontendHttpControllerTest.php @@ -13,7 +13,7 @@ public function testHttpController(): void $text = 'Frontier by HTTP'; Http::fake([ - 'localhost' => Http::response($text), + 'frontier.test' => Http::response($text), ]); $this->get('/http') diff --git a/tests/FrontendProxyControllerTest.php b/tests/FrontendProxyControllerTest.php index 67dee6d..148f8f9 100644 --- a/tests/FrontendProxyControllerTest.php +++ b/tests/FrontendProxyControllerTest.php @@ -11,7 +11,7 @@ public function testProxyController(): void $text = 'Frontier by Proxy'; Http::fake([ - 'localhost/proxy-uri' => Http::response($text), + 'frontier.test/proxy-uri' => Http::response($text), ]); $this->get('/proxy-uri') diff --git a/tests/TestCase.php b/tests/TestCase.php index bc18297..68114c7 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -21,7 +21,7 @@ protected function defineEnvironment($app): void 'http' => [ 'type' => 'http', 'endpoint' => 'http', - 'view' => 'http://localhost', + 'view' => 'http://frontier.test', 'cache' => false, 'proxy' => [ 'proxy-uri' @@ -30,7 +30,7 @@ protected function defineEnvironment($app): void 'http-with-cache' => [ 'type' => 'http', 'endpoint' => 'http-with-cache', - 'view' => 'http://localhost', + 'view' => 'http://frontier.test', 'cache' => true, ], 'view' => [