Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs and config #20

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
Loading