유니티 웹을 위한 php 자체 서버 용 router.php

new
php -S 127.0.0.1:81 router.php

주요 해더 설정이 동작안하므로 그걸 임으로 동작하게 하는 라우트 파일 설정함.



------------------------ router.php
<?php

$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$file = __DIR__ . urldecode($uri); //$uri;
// var_dump(is_file($file));
// exit($file);

if (is_file($file)) {

    $mimeTypes = [
        'html' => 'text/html; charset=UTF-8',
        'htm'  => 'text/html; charset=UTF-8',
        'js'   => 'application/javascript',
        'mjs'  => 'application/javascript',
        'css'  => 'text/css',
        'json' => 'application/json',
        'xml'  => 'application/xml',
        'txt'  => 'text/plain',

        'png'  => 'image/png',
        'jpg'  => 'image/jpeg',
        'jpeg' => 'image/jpeg',
        'gif'  => 'image/gif',
        'webp' => 'image/webp',
        'svg'  => 'image/svg+xml',
        'ico'  => 'image/x-icon',

        'mp3'  => 'audio/mpeg',
        'wav'  => 'audio/wav',
        'ogg'  => 'audio/ogg',

        'mp4'  => 'video/mp4',
        'webm' => 'video/webm',

        'wasm' => 'application/wasm',
        'data' => 'application/octet-stream',
    ];

    
    // Unity Brotli 압축 파일 처리
    if (substr($file, -3) === '.br') {

        header('Content-Encoding: br');

        if (substr($file, -6) === '.js.br') {
            header('Content-Type: application/javascript');
        }
        elseif (substr($file, -8) === '.wasm.br') {
            header('Content-Type: application/wasm');
        }
        elseif (substr($file, -8) === '.data.br') {
            header('Content-Type: application/octet-stream');
        }
        elseif (substr($file, -8) === '.css.br') {
            header('Content-Type: text/css');
        }

        readfile($file);
        exit;
    }

    $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));

    if (isset($mimeTypes[$ext])) {
        header('Content-Type: ' . $mimeTypes[$ext]);
    } else {
        header('Content-Type: application/octet-stream');
    }

    readfile($file);
    exit;
}

return false;


댓글
  • No Nickname
    No Comment
  • 권한이 없습니다.
    {{m_row.m_nick}}
    -
목록형 📷 갤러리형
제목
[기본형] HTML (with 부트스트랩5.3 , jquery 3.7, vue.js)
유용한 리눅스(LINUX) 명령어
[공지] 기술 게시판
5.31
6.1
6.2
6.3
6.4
6.5
6.6
6.7
6.8
6.9
6.10
6.11
6.13
6.14
6.15
6.16
6.17
6.18
6.19
6.20
6.21
6.22
6.23
6.24
6.25
6.26
6.27
6.28
6.29
6.30
7.1
7.2
7.3
7.4