From 01308b1b667229148877489c4b4bd191d6c77f85 Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Tue, 18 Jun 2024 13:38:06 -0300 Subject: [PATCH 1/4] Add tests --- tests/FrontendProxyControllerTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/FrontendProxyControllerTest.php b/tests/FrontendProxyControllerTest.php index d1f3722..a86b44a 100644 --- a/tests/FrontendProxyControllerTest.php +++ b/tests/FrontendProxyControllerTest.php @@ -13,6 +13,7 @@ 'rules' => [ '/favicon.ico::exact', '/exact/replace::exact::replace(/exact/replace,https://frontier.test/another/exact/replace)', + '/replace::replace(/replace)', '/all::replace(Replace,is amazing!)', '/web', ], @@ -79,3 +80,13 @@ ->assertContent('Frontier is amazing!') ->assertOk(); }); + +test('proxy and replace using base URL', function () { + Http::fake([ + 'frontier.test/replace/*' => Http::response('Frontier is running in: /replace'), + ]); + + $this->get('/replace') + ->assertContent('Frontier is running in: frontier.test/replace') + ->assertOk(); +}); From 8df51ada510362eaac4cc7360fb6c25f82965cc7 Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Tue, 18 Jun 2024 13:43:33 -0300 Subject: [PATCH 2/4] Retro compatibility with `proxy` approach --- config/frontier.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/frontier.php b/config/frontier.php index e86b504..34e95fc 100644 --- a/config/frontier.php +++ b/config/frontier.php @@ -38,6 +38,11 @@ 'headers' => [ 'Accept' => 'text/html', ], + + 'host' => env('FRONTIER_PROXY_HOST', ''), + + 'rules' => array_filter(explode('|', env('FRONTIER_PROXY_RULES', ''))), + ], 'proxy' => [ From d86c412dc5925590f466efa693a8a3957775e79c Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Tue, 18 Jun 2024 14:03:00 -0300 Subject: [PATCH 3/4] Fallback for config --- config/frontier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/frontier.php b/config/frontier.php index 34e95fc..f797f44 100644 --- a/config/frontier.php +++ b/config/frontier.php @@ -49,7 +49,7 @@ 'type' => 'proxy', - 'host' => env('FRONTIER_PROXY_HOST', ''), + 'host' => env('FRONTIER_PROXY_HOST', env('FRONTIER_VIEW', '')), 'rules' => array_filter(explode('|', env('FRONTIER_PROXY_RULES', ''))), From e8179c7a7c3925dc5a30c70da77e3a56de6f6ef8 Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Tue, 18 Jun 2024 14:03:04 -0300 Subject: [PATCH 4/4] Docs --- README.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 30090ac..40d326e 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ You can configure your frontend using some environment variables described below | `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` | +| `FRONTIER_PROXY_HOST` | `url` of the assets server | | +| `FRONTIER_PROXY_RULES` | Proxy rules | | ### Frontend types @@ -45,7 +47,9 @@ Use in `FRONTIER_VIEW` the URL of your frontend server. #### Proxy -Use in `FRONTIER_VIEW` the URL of your real server. +Use in `FRONTIER_PROXY_HOST` or `FRONTIER_VIEW` the URL of your frontend server. + +> `FRONTIER_VIEW` will be removed in the future. #### View @@ -56,7 +60,7 @@ Use in `FRONTIER_VIEW` the name of your view that you initialize your frontend, #### 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. +environment variables using `http` approach. ```bash FRONTIER_ENDPOINT=/vue @@ -68,6 +72,15 @@ FRONTIER_PROXY=/vite.svg FRONTIER_CACHE=false ``` +#### Nuxt.js + +When using [Nuxt](https://nuxt.com/) you can start your project with these environment variables using `proxy` approach. + +```bash +FRONTIER_PROXY_HOST=http://localhost:3000 +FRONTIER_PROXY_RULES=/_vfs.json::exact|/favicon.ico::exact::rewrite(/favicon.ico)|/__nuxt_devtools__/client/_nuxt/builds/meta|/__nuxt_devtools__/client::replace(/__nuxt_devtools__/client/_nuxt/)|/_nuxt|/_fonts|/::replace(/_nuxt/) +``` + ### Multiple frontends You can run multiple frontends, just create a custom configuration file.