feat(api): 初始化笔记应用后端基础架构
- 添加环境配置文件 .env.example 包含数据库、JWT、CORS等配置 - 创建 .gitignore 文件忽略敏感文件和临时文件 - 配置 Apache 重写规则支持路由转发 - 实现 JWT 认证中间件提供用户身份验证功能 - 添加 MySQL 数据库初始化脚本包含分组、图片、笔记表结构
This commit is contained in:
4
biji-php/public/.htaccess
Normal file
4
biji-php/public/.htaccess
Normal file
@@ -0,0 +1,4 @@
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^ index.php [QSA,L]
|
||||
37
biji-php/public/index.php
Normal file
37
biji-php/public/index.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Slim\Factory\AppFactory;
|
||||
use DI\Container;
|
||||
use Dotenv\Dotenv;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// 加载环境变量
|
||||
$dotenv = Dotenv::createImmutable(__DIR__ . '/..');
|
||||
$dotenv->load();
|
||||
|
||||
// 创建容器
|
||||
$container = new Container();
|
||||
AppFactory::setContainer($container);
|
||||
|
||||
// 创建应用
|
||||
$app = AppFactory::create();
|
||||
|
||||
// 添加路由中间件(必须在路由定义之前)
|
||||
$app->addRoutingMiddleware();
|
||||
|
||||
// 添加错误处理
|
||||
$app->addErrorMiddleware(true, true, true);
|
||||
|
||||
// 添加 CORS 中间件
|
||||
$app->add(new \App\Middleware\CorsMiddleware());
|
||||
|
||||
// 处理 OPTIONS 请求
|
||||
$app->options('/{routes:.+}', function ($request, $response) {
|
||||
return $response;
|
||||
});
|
||||
|
||||
// 加载路由
|
||||
require __DIR__ . '/../config/routes.php';
|
||||
|
||||
$app->run();
|
||||
Reference in New Issue
Block a user