Skip to content

Instantly share code, notes, and snippets.

@BARNZ
Created January 15, 2017 04:24
Show Gist options
  • Save BARNZ/0f74f6d58ddf2d9e97ed3e03fd021b2c to your computer and use it in GitHub Desktop.
Save BARNZ/0f74f6d58ddf2d9e97ed3e03fd021b2c to your computer and use it in GitHub Desktop.
Laravel 5.x middleware to retrieve the version number from Node JS package.json
<?php
namespace App\Http\Middleware;
use Closure;
/**
* Reads the current version of the app into an APP_VERSION variable by reading
* the applications Node JS package.json file.
*
* Version number can be read back out using: config('APP_VERSION')
*/
class AppVersion
{
public function handle($request, Closure $next)
{
$metadata = json_decode(file_get_contents(base_path('package.json')));
\Config::set('APP_VERSION', $metadata->version);
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment