<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2019 http://thinkphp.cn     All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0  )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

// [ 应用入口文件 ]
namespace think;

require __DIR__ . '/../vendor/autoload.php';

$url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

/* ---- 1. 安装锁检测（原逻辑） ---- */
$whe = !str_starts_with($url, '/adminapi/config/getConfig') &&
       !str_starts_with($url, '/api/pc/config') &&
       !str_starts_with($url, '/api/index/config');
if ($whe && !file_exists(__DIR__ . '/../config/install.lock')) {
    header("location:/install/install.php");
    exit;
}

/* ---- 2. PC 端统一重定向到 /api/notifypc ---- */
if (preg_match('#^/api/Report/(\d+)/pc$#i', $_SERVER['REQUEST_URI'], $m)) {
    $_SERVER['REQUEST_URI'] = '/api/notifypc';
    $_GET['s'] = '/api/notifypc';   // 关键：让 TP 用这条路由
}

/* ---- 3. 原有 HTTP 运行逻辑 ---- */
$is_admin = str_starts_with($url, '/admin');
$http = (new App())->http;
$response = $is_admin ? $http->run() : $http->name('index')->run();
$response->send();
$http->end($response);