<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Support\Facades\Route;

return Application::configure(basePath: dirname(__DIR__))
    // (A) Routing: 도메인별 라우트 분리
    ->withRouting(
        web: __DIR__.'/../routes/web.php',   // 공용(가능하면 최소화)
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
        then: function () {
            Route::middleware('web')
                ->domain('four.syye.net')
                ->group(base_path('routes/web.php'));

            Route::middleware('web')
                ->domain('shot.syye.net')
                ->group(base_path('routes/admin.php'));
        },
    )

    // (B) Middleware: Reverse Proxy/Host 신뢰 정책
    ->withMiddleware(function (Middleware $middleware): void {
        $middleware->trustProxies(at: [
            '192.168.100.0/24',
            '127.0.0.0/8',
            '10.0.0.0/8',
            '172.16.0.0/12',
        ]);

        $middleware->trustHosts(at: [
            'four.syye.net',
            'shot.syye.net',
        ]);
    })

    ->withExceptions(function (Exceptions $exceptions): void {
        //
    })

    ->create();
