Skip to content

Commit

Permalink
Merge pull request #20 from edersoares/docs
Browse files Browse the repository at this point in the history
Docs and config
  • Loading branch information
edersoares authored Jun 18, 2024
2 parents 5756c8f + e8179c7 commit 3f460d7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand All @@ -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
Expand All @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion config/frontier.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@
'headers' => [
'Accept' => 'text/html',
],

'host' => env('FRONTIER_PROXY_HOST', ''),

'rules' => array_filter(explode('|', env('FRONTIER_PROXY_RULES', ''))),

],

'proxy' => [

'type' => 'proxy',

'host' => env('FRONTIER_PROXY_HOST', ''),
'host' => env('FRONTIER_PROXY_HOST', env('FRONTIER_VIEW', '')),

'rules' => array_filter(explode('|', env('FRONTIER_PROXY_RULES', ''))),

Expand Down
11 changes: 11 additions & 0 deletions tests/FrontendProxyControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down Expand Up @@ -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();
});

0 comments on commit 3f460d7

Please sign in to comment.