Cleanup
This commit is contained in:
1 parent
b53047a28c
commit
42404cc2cc
9 files changed
+79
-136
No files matched your search
+2
-30
@@ -1,34 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use MattitjaAB\LaravelPlausibleProxy\Http\Controllers\PlausibleScriptProxyController;
|
||||
|
||||
Route::get('/js/script.js', function () {
|
||||
$plausibleDomain = config('plausible-proxy.domain');
|
||||
|
||||
if (Cache::has('plausible_script_js')) {
|
||||
return response(Cache::get('plausible_script_js'))
|
||||
->header('Content-Type', 'application/javascript')
|
||||
->header('Cache-Control', 'public, max-age=86400');
|
||||
}
|
||||
|
||||
$response = Http::timeout(5)->get("{$plausibleDomain}/js/script.js");
|
||||
|
||||
if ($response->successful()) {
|
||||
$script = $response->body();
|
||||
Cache::put('plausible_script_js', $script, now()->addHours(6));
|
||||
|
||||
return response($script)
|
||||
->header('Content-Type', 'application/javascript')
|
||||
->header('Cache-Control', 'public, max-age=86400');
|
||||
}
|
||||
|
||||
return response('Error fetching Plausible script', 500);
|
||||
});
|
||||
|
||||
Route::get('/api/routes', function () {
|
||||
return response()->json(
|
||||
collect(Route::getRoutes())->map(fn ($route) => $route->uri())
|
||||
);
|
||||
});
|
||||
Route::get('/js/script.js', PlausibleScriptProxyController::class);
|
||||
Reference in new issue
Block a user