Created
January 15, 2017 04:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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