mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-03 18:40:52 +08:00
fix(runtime): force app_url/force_https per-request via middlewar
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
use App\Support\Setting;
|
use App\Support\Setting;
|
||||||
use Illuminate\Support\Facades\App;
|
|
||||||
|
|
||||||
if (!function_exists('admin_setting')) {
|
if (!function_exists('admin_setting')) {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ class Kernel extends HttpKernel
|
|||||||
// \Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
// \Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||||
// \App\Http\Middleware\VerifyCsrfToken::class,
|
// \App\Http\Middleware\VerifyCsrfToken::class,
|
||||||
// \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
// \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
\App\Http\Middleware\ApplyRuntimeSettings::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
'api' => [
|
'api' => [
|
||||||
@@ -46,6 +47,7 @@ class Kernel extends HttpKernel
|
|||||||
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
||||||
// \Illuminate\Routing\Middleware\ThrottleRequests::class . ':api',
|
// \Illuminate\Routing\Middleware\ThrottleRequests::class . ':api',
|
||||||
// \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
// \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
\App\Http\Middleware\ApplyRuntimeSettings::class,
|
||||||
\App\Http\Middleware\ForceJson::class,
|
\App\Http\Middleware\ForceJson::class,
|
||||||
\App\Http\Middleware\Language::class,
|
\App\Http\Middleware\Language::class,
|
||||||
'bindings',
|
'bindings',
|
||||||
|
|||||||
25
app/Http/Middleware/ApplyRuntimeSettings.php
Normal file
25
app/Http/Middleware/ApplyRuntimeSettings.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\URL;
|
||||||
|
|
||||||
|
class ApplyRuntimeSettings
|
||||||
|
{
|
||||||
|
public function handle(Request $request, Closure $next)
|
||||||
|
{
|
||||||
|
$appUrl = admin_setting('app_url');
|
||||||
|
if (is_string($appUrl) && $appUrl !== '') {
|
||||||
|
URL::forceRootUrl($appUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((bool) admin_setting('force_https', false)) {
|
||||||
|
URL::forceScheme('https');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -23,11 +23,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
//
|
// HTTPS scheme is forced per-request via middleware (Octane-safe).
|
||||||
if (admin_setting('force_https')) {
|
|
||||||
resolve(\Illuminate\Routing\UrlGenerator::class)->forceScheme('https');
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::boot();
|
parent::boot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,8 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\Support\Setting;
|
use App\Support\Setting;
|
||||||
use Illuminate\Support\Facades\URL;
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
class SettingServiceProvider extends ServiceProvider
|
class SettingServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@@ -30,8 +28,6 @@ class SettingServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
if ($appUrl = admin_setting('app_url')) {
|
// App URL is forced per-request via middleware (Octane-safe).
|
||||||
URL::forceRootUrl($appUrl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,6 +239,11 @@ class ServerService
|
|||||||
default => [],
|
default => [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$response = array_filter(
|
||||||
|
$response,
|
||||||
|
static fn ($value) => $value !== null
|
||||||
|
);
|
||||||
|
|
||||||
if (!empty($node['route_ids'])) {
|
if (!empty($node['route_ids'])) {
|
||||||
$response['routes'] = self::getRoutes($node['route_ids']);
|
$response['routes'] = self::getRoutes($node['route_ids']);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user