Skip to content

Commit

Permalink
Merge pull request #10 from edersoares/misc
Browse files Browse the repository at this point in the history
Miscellaneous
  • Loading branch information
edersoares authored Jun 9, 2023
2 parents 54fcab6 + a73be12 commit 6cde997
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 28 deletions.
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
43 changes: 23 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -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": [
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion tests/FrontendHttpControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/FrontendProxyControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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' => [
Expand Down

0 comments on commit 6cde997

Please sign in to comment.