Files
Atomcms-edit/app/Providers/RouteServiceProvider.php
root 0c6c558a59 Add radio embed widget, SSE real-time, song history, moderation panel, and Auto DJ
- Embed widget: standalone iframe player with dark/light/transparent themes, copy-paste embed code admin page
- Real-time SSE: streaming now-playing/listeners/dj events, replaces polling in radio-player and embed
- Song history: auto-records song changes to radio_song_plays table, Filament resource to view
- DJ moderation: unified panel for shouts approval, song request queue, DJ applications
- Auto DJ: playlist management with round-robin playback when no DJ is live
- Refactored radio-player Alpine component to use EventSource API with auto-reconnect
2026-05-24 14:07:32 +02:00

81 lines
2.5 KiB
PHP
Executable File

<?php
declare(strict_types=1);
namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* Typically, users are redirected here after authentication.
*
* @var string
*/
public const HOME = '/user/me';
/**
* Define your route model bindings, pattern filters, and other route configuration.
*/
#[\Override]
public function boot(): void
{
$this->configureRateLimiting();
$this->routes(function () {
Route::middleware('api')
->prefix('api')
->group(base_path('routes/api.php'));
Route::middleware('web')
->group(base_path('routes/web.php'));
});
}
/**
* Configure the rate limiters for the application.
*/
protected function configureRateLimiting(): void
{
// API rate limit: 150 per minute for authenticated users, 100 for guests
RateLimiter::for('api', function (Request $request) {
$userId = $request->user()?->id;
$key = $userId ?: $request->ip();
$maxAttempts = $userId ? 150 : 100;
return Limit::perMinute($maxAttempts)->by($key);
});
// Web rate limit for authenticated users
RateLimiter::for('web', function (Request $request) {
$userId = $request->user()?->id;
$key = $userId ?: $request->ip();
$maxAttempts = $userId ? 200 : 100;
return Limit::perMinute($maxAttempts)->by($key);
});
// Strict rate limit for login attempts (security) - increased for usability
RateLimiter::for('login', fn (Request $request) => Limit::perMinute(20)->by($request->ip()));
// Two-factor authentication rate limit
RateLimiter::for('two-factor', fn (Request $request) => Limit::perMinute(15)->by($request->ip()));
// Rate limit for radio endpoints (high traffic)
RateLimiter::for('radio', function (Request $request) {
$key = $request->get('radio_api_key_id')
?? $request->user()?->id
?? $request->ip();
return Limit::perMinute(120)->by((string) $key);
});
}
}