Skip to content

Commit 5188834

Browse files
committed
feat: add optional JSON API with Bearer token authentication
Expose read/write JSON endpoints for dashboards and integrations when `vantage.api.enabled` is true, separate from the Blade dashboard Gate.
1 parent 336026a commit 5188834

5 files changed

Lines changed: 491 additions & 1 deletion

File tree

config/vantage.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,28 @@
108108
'routes' => env('VANTAGE_ROUTES', true),
109109
'route_prefix' => env('VANTAGE_ROUTE_PREFIX', 'vantage'),
110110

111+
/*
112+
|--------------------------------------------------------------------------
113+
| REST / JSON API
114+
|--------------------------------------------------------------------------
115+
|
116+
| Expose a JSON API for external consumption (dashboards, CLI tools, etc.).
117+
| The API is independent of the web dashboard and uses Bearer-token auth
118+
| instead of the Gate/session-based auth used by the Blade views.
119+
|
120+
| Set `api.token` to a strong random string and pass it as:
121+
| Authorization: Bearer <token>
122+
|
123+
| If the token contains =, +, #, or spaces, wrap the value in double quotes
124+
| in your .env file (e.g. VANTAGE_API_TOKEN="...") so it is not truncated.
125+
|
126+
*/
127+
'api' => [
128+
'enabled' => env('VANTAGE_API_ENABLED', false),
129+
'token' => env('VANTAGE_API_TOKEN'),
130+
'prefix' => env('VANTAGE_API_PREFIX', 'api/vantage'),
131+
],
132+
111133
/*
112134
|--------------------------------------------------------------------------
113135
| Performance Telemetry

routes/api.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Route;
4+
use Storvia\Vantage\Http\Controllers\VantageApiController;
5+
use Storvia\Vantage\Http\Middleware\AuthorizeVantageApi;
6+
7+
$prefix = trim(config('vantage.api.prefix', 'api/vantage'), '/');
8+
$prefix = $prefix === '' ? 'api/vantage' : $prefix;
9+
10+
Route::prefix($prefix)->name('vantage.api.')->middleware(AuthorizeVantageApi::class)->group(function () {
11+
Route::get('/', [VantageApiController::class, 'index'])->name('index');
12+
Route::get('/stats', [VantageApiController::class, 'stats'])->name('stats');
13+
Route::get('/jobs', [VantageApiController::class, 'jobs'])->name('jobs');
14+
Route::get('/jobs/{id}', [VantageApiController::class, 'show'])->name('jobs.show');
15+
Route::get('/tags', [VantageApiController::class, 'tags'])->name('tags');
16+
Route::get('/failed', [VantageApiController::class, 'failed'])->name('failed');
17+
Route::post('/jobs/{id}/retry', [VantageApiController::class, 'retry'])->name('jobs.retry');
18+
Route::get('/queue-depths', [VantageApiController::class, 'queueDepths'])->name('queue-depths');
19+
Route::get('/batches', [VantageApiController::class, 'batches'])->name('batches');
20+
});

0 commit comments

Comments
 (0)