Files
Virtnet.bond/bootstrap/app.php

107 lines
4.1 KiB
PHP

<?php
use App\Http\Middleware\Api\AdminApi;
use App\Http\Middleware\EnsureUserHasPermissions;
use App\Http\Middleware\ImpersonateMiddleware;
use App\Http\Middleware\ProxyMiddleware;
use App\Http\Middleware\SetLocale;
use App\Models\DebugLog;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Laravel\Passport\Http\Middleware\CheckForAnyScope;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__ . '/../routes/web.php',
api: __DIR__ . '/../routes/api.php',
commands: __DIR__ . '/../routes/console.php',
// channels: __DIR__.'/../routes/channels.php',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->append(ProxyMiddleware::class);
$middleware->alias([
'has' => EnsureUserHasPermissions::class,
'scope' => CheckForAnyScope::class,
'api.admin' => AdminApi::class,
]);
$middleware->web([
SetLocale::class,
ImpersonateMiddleware::class,
]);
})
->withEvents(discover: [
__DIR__ . '/../app/Extensions',
__DIR__ . '/../app/Listeners',
])
->withExceptions(function (Exceptions $exceptions) {
$exceptions->report(function (Exception $exception) {
try {
if (!config('settings.debug', false)) {
return;
}
DebugLog::create([
'type' => 'exception',
'context' => [
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTraceAsString(),
],
]);
} catch (Exception $e) {
// Do nothing
throw $e;
}
});
// #region agent log
$exceptions->report(function (\Throwable $e) {
try {
$reqPath = '';
try {
$reqPath = request()?->path() ?? '';
} catch (\Throwable) {
}
$msg = $e->getMessage();
$file = $e->getFile();
$trace = $e->getTraceAsString();
$normFile = str_replace('\\', '/', $file);
$normTrace = str_replace('\\', '/', $trace);
$relevant = str_contains(strtolower((string) $reqPath), 'statistics')
|| str_contains(strtolower((string) $reqPath), 'livewire')
|| str_contains(strtolower($msg), 'statistics.blade')
|| str_contains(strtolower($msg), 'unable to locate a class or view for component')
|| str_contains($msg, 'proxmox::')
|| str_contains($normTrace, 'Servers/Proxmox/Livewire/Statistics')
|| str_contains($normFile, 'Servers/Proxmox/');
if (!$relevant) {
return;
}
$payload = [
'sessionId' => 'd17155',
'runId' => 'pre-fix',
'hypothesisId' => 'H_exc',
'timestamp' => (int) round(microtime(true) * 1000),
'location' => 'bootstrap/app.php:withExceptions.report',
'message' => 'statistics_related_exception',
'data' => [
'class' => $e::class,
'msg' => $msg,
'file' => $file,
'line' => $e->getLine(),
'reqPath' => $reqPath,
],
];
file_put_contents(
base_path('debug-d17155.log'),
json_encode($payload, JSON_UNESCAPED_SLASHES) . "\n",
FILE_APPEND | LOCK_EX
);
} catch (\Throwable) {
}
});
// #endregion
})->create();