Files
docs/thinkphp/route/route.php
cenzuhai 3a04eede84 feat: 初始化进销存数据开放平台项目
初始化完整的前后端项目结构,包含ThinkPHP后端API服务和Next.js前端管理系统,添加基础配置、中间件、模型、路由等核心代码,以及项目文档和静态资源。
2026-07-08 17:48:00 +08:00

65 lines
2.0 KiB
PHP

<?php
use think\facade\Route;
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
Route::miss(function () {
$appRequest = request()->pathinfo();
if ($appRequest === null) {
$appName = '';
} else {
$appRequest = str_replace('//', '/', $appRequest);
$appName = explode('/', $appRequest)[0] ?? '';
}
$publicPath = app()->getRootPath() . 'public' . DS;
$staticExtensions = ['js', 'css', 'png', 'jpg', 'jpeg', 'gif', 'svg', 'ico', 'woff', 'woff2', 'ttf', 'eot'];
$pathParts = explode('.', $appRequest);
$extension = strtolower(end($pathParts));
if (in_array($extension, $staticExtensions)) {
$filePath = $publicPath . $appRequest;
if (file_exists($filePath)) {
$mimeTypes = [
'js' => 'application/javascript',
'css' => 'text/css',
'png' => 'image/png',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'gif' => 'image/gif',
'svg' => 'image/svg+xml',
'ico' => 'image/x-icon',
'woff' => 'font/woff',
'woff2' => 'font/woff2',
'ttf' => 'font/ttf',
'eot' => 'application/vnd.ms-fontobject',
];
header('Content-Type: ' . ($mimeTypes[$extension] ?? 'application/octet-stream'));
return file_get_contents($filePath);
}
}
switch (strtolower($appName)) {
case 'admin':
$filePath = $publicPath . 'admin' . DS . 'index.html';
break;
case 'home':
case 'pages':
default:
$filePath = $publicPath . 'admin' . DS . 'client.html';
break;
}
if (file_exists($filePath)) {
header('Content-Type: text/html; charset=UTF-8');
return file_get_contents($filePath);
}
return json([
'code' => 404,
'msg' => '页面不存在'
], 404);
});