v1.1.1页面修复

This commit is contained in:
2026-05-07 12:46:32 +08:00
parent e40fe98b42
commit 80b71a973a
3 changed files with 62 additions and 6 deletions

View File

@@ -38,6 +38,7 @@ ai-chat/
├── public/ # Web 根目录Nginx 指向此目录) ├── public/ # Web 根目录Nginx 指向此目录)
│ ├── index.php # 首页入口(自动路由到登录/安装页) │ ├── index.php # 首页入口(自动路由到登录/安装页)
│ ├── api.php # API 统一入口 │ ├── api.php # API 统一入口
│ ├── router.php # PHP 内置开发服务器路由文件
│ ├── login.php # 登录页面 │ ├── login.php # 登录页面
│ ├── chat.php # 聊天主页面 │ ├── chat.php # 聊天主页面
│ ├── config.php # 配置管理页面 │ ├── config.php # 配置管理页面
@@ -84,21 +85,27 @@ ai-chat/
composer install composer install
``` ```
3. **配置 Nginx** 3. **启动开发服务器**(本地开发)
```bash
php -S localhost:8080 -t public/ public/router.php
```
然后访问 `http://localhost:8080/`
4. **或配置 Nginx**(生产部署)
- 将网站根目录指向 `public/` 目录 - 将网站根目录指向 `public/` 目录
- 参考 `docs/nginx.conf` 或 `docs/baota-nginx-snippet.conf` 配置 Nginx - 参考 `docs/nginx.conf` 或 `docs/baota-nginx-snippet.conf` 配置 Nginx
4. **设置目录权限** 5. **设置目录权限**(生产部署)
```bash ```bash
chmod -R 755 . chmod -R 755 .
chown -R www:www . chown -R www:www .
``` ```
5. **运行安装向导** 6. **运行安装向导**
- 访问 `http://your-domain.com/install.php` - 访问 `http://your-domain.com/install.php`
- 按照向导步骤完成安装 - 按照向导步骤完成安装
详细安装说明请查看 [INSTALL.md](INSTALL.md)。 详细安装说明请查看 [INSTALL.md](INSTALL.md) 和 [DEPLOY.md](docs/DEPLOY.md)
## 页面说明 ## 页面说明

View File

@@ -75,10 +75,19 @@ const InstallWizard = {
database: document.getElementById('dbName').value database: document.getElementById('dbName').value
}) })
}); });
const data = await response.json();
const text = await response.text();
let data;
try {
data = JSON.parse(text);
} catch (parseErr) {
result.innerHTML = '<div class="alert alert-error">服务器返回了非 JSON 响应HTTP ' + response.status + ')。请检查 Web 服务器是否正确配置了 /api/ 路由转发。<details><summary>原始响应</summary><pre>' + text.replace(/</g, '<').substring(0, 500) + '</pre></details></div>';
return;
}
result.innerHTML = `<div class="alert ${data.success ? 'alert-success' : 'alert-error'}">${data.message}</div>`; result.innerHTML = `<div class="alert ${data.success ? 'alert-success' : 'alert-error'}">${data.message}</div>`;
} catch (err) { } catch (err) {
result.innerHTML = '<div class="alert alert-error">连接失败: ' + err.message + '</div>'; result.innerHTML = '<div class="alert alert-error">请求失败: ' + err.message + '</div>';
} }
}, },

40
public/router.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
/**
* PHP 内置开发服务器路由文件
*
* 用法php -S localhost:8080 -t public/ public/router.php
*
* Nginx 部署不需要此文件Nginx 有自己的 URL 重写规则。
*/
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
// API 路由 — 所有 /api/ 请求统一转发到 api.php
if (str_starts_with($uri, '/api/')) {
require __DIR__ . '/api.php';
return true;
}
// 静态资源CSS/JS/图片/字体/上传文件等)
if ($uri !== '/' && preg_match('/\.(css|js|png|jpg|jpeg|gif|ico|svg|woff2?|ttf|eot|webp|webm|mp4|pdf|zip)$/i', $uri)) {
$file = __DIR__ . $uri;
if (is_file($file)) {
return false; // 让 PHP 内置服务器直接返回静态文件
}
}
// 根路径
if ($uri === '/' || $uri === '') {
require __DIR__ . '/index.php';
return true;
}
// 已存在的 PHP 文件直接访问
$phpFile = __DIR__ . $uri;
if (is_file($phpFile) && str_ends_with($uri, '.php')) {
return false; // 让 PHP 内置服务器处理
}
// 其他请求回退到 index.php
require __DIR__ . '/index.php';
return true;