|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2026 OpenStack Foundation |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + **/ |
| 14 | + |
| 15 | +use Illuminate\Support\Facades\Route; |
| 16 | + |
| 17 | +/* |
| 18 | +|-------------------------------------------------------------------------- |
| 19 | +| Public API Routes |
| 20 | +|-------------------------------------------------------------------------- |
| 21 | +| |
| 22 | +| Public API endpoints that do not require authentication. |
| 23 | +| |
| 24 | +*/ |
| 25 | + |
| 26 | +Route::get('/version', function () { |
| 27 | + $versionFile = base_path('version.json'); |
| 28 | + |
| 29 | + // Check if file exists |
| 30 | + if (!file_exists($versionFile)) { |
| 31 | + return response()->json(['error' => 'Version information not found'], 404); |
| 32 | + } |
| 33 | + |
| 34 | + // Read file contents |
| 35 | + $contents = file_get_contents($versionFile); |
| 36 | + |
| 37 | + // Decode JSON |
| 38 | + $versionData = json_decode($contents, true); |
| 39 | + |
| 40 | + // Check if JSON is valid or empty |
| 41 | + if ($versionData === null && json_last_error() !== JSON_ERROR_NONE) { |
| 42 | + return response()->json(['error' => 'Version information malformed'], 412); |
| 43 | + } |
| 44 | + |
| 45 | + if (empty($versionData)) { |
| 46 | + return response()->json(['error' => 'Version information malformed'], 412); |
| 47 | + } |
| 48 | + |
| 49 | + return response()->json($versionData, 200); |
| 50 | +}); |
0 commit comments