Skip to content

Commit

Permalink
Add domain configuration option
Browse files Browse the repository at this point in the history
Fixes #35
  • Loading branch information
mikebronner committed Sep 3, 2016
1 parent d107246 commit bbeb209
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,21 @@ existing routes.
```

## Configuration
To change the default drip interval of 5 minutes, simply publish the configuration file:
The following elements are configurable:
- **domain:** (default: `url('/')`) Change to point to a different domain than
your app. This is useful if you are behind a proxy or load-balancer.
- **route:** (default: `genealabs/laravel-caffeine/drip`) Change to customize
the drip URL in the browser. This is just cosmetic.
- **dripIntervalInMilliSeconds:** (default: 5 mins) Change to configure the drip
interval.

You only need to publish the config file it you want to customize it:
```sh
php artisan vendor:publish --tag=genealabs-laravel-caffeine
```

You can now change the default value in `/app/config/genealabs-laravel-caffeine.php` as desired. Deleting the
`/app/config/genealabs-laravel-caffeine.php` file will revert back to the default 5-minute interval.
`/app/config/genealabs-laravel-caffeine.php` file will revert back to the default settings.

## Usage
That was it! It will apply itself automatically where it finds a form with a `_token` field, or a meta tag named
Expand Down
44 changes: 18 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
{
"name": "genealabs/laravel-caffeine",
"description": "Keeping Your Laravel Forms Awake",
"license": "MIT",
"authors": [
{
"name": "Mike Bronner",
"email": "hello@genealabs.com"
"name": "genealabs/laravel-caffeine",
"description": "Keeping Your Laravel Forms Awake",
"license": "MIT",
"authors": [
{
"name": "Mike Bronner",
"email": "hello@genealabs.com"
}
],
"autoload": {
"psr-4": {
"GeneaLabs\\LaravelCaffeine\\": "src/"
}
},
"require": {
"php": ">=5.5.0",
"illuminate/support": "~5.1",
"illuminate/routing": "~5.1"
}
],
"autoload": {
"psr-4": {
"GeneaLabs\\LaravelCaffeine\\": "src/"
}
},
"require": {
"php": ">=5.5.0",
"illuminate/support": "~5.1",
"illuminate/routing": "~5.1"
},
"require-dev": {
"phpunit/phpunit": "4.*"
},
"autoload-dev": {
"psr-4": {
"GeneaLabs\\LaravelCaffein\\Tests\\": "tests/"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

return [
'dripIntervalInMilliSeconds' => 300000,
'domain' => url('/'),
'route' => 'genealabs/laravel-caffeine/drip',
];
4 changes: 3 additions & 1 deletion src/Http/Middleware/LaravelCaffeineDripMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public function handle($request, Closure $next)
&& (strpos($content, '_token')
|| (preg_match("/\<meta name=[\"\']csrf[_-]token[\"\']/", $content)))
) {
$dripUrl = url(config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip'));
$domain = config('genealabs-laravel-caffeine.domain', url('/'));
$route = config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip');
$dripUrl = trim($domain, ' /') . "/" . trim($route, ' /');
$interval = config('genealabs-laravel-caffeine.dripIntervalInMilliSeconds', 300000);

$newContent = '<script>setInterval(function(){';
Expand Down
4 changes: 2 additions & 2 deletions src/LaravelCaffeineServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public function boot()
require __DIR__ . '/Http/routes.php';
}

$this->publishes([__DIR__ . '/../config/config.php' => config_path('genealabs-laravel-caffeine.php')], 'genealabs-laravel-caffeine');
$this->publishes([__DIR__ . '/../config/genealabs-laravel-caffeine.php' => config_path('genealabs-laravel-caffeine.php')], 'genealabs-laravel-caffeine');
}

public function register()
{
// Nothing to see here, folks ...
$this->mergeConfigFrom(__DIR__ . '/../config/genealabs-laravel-caffeine.php', 'genealabs-laravel-caffeine');
}

/**
Expand Down

0 comments on commit bbeb209

Please sign in to comment.