diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 5529ef7..a7a321f 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -40,6 +40,7 @@ class Kernel extends HttpKernel 'api' => [ \App\Http\Middleware\ValidateHeaders::class, + \App\Http\Middleware\CustomCors::class, \Illuminate\Routing\Middleware\ThrottleRequests::class.':api', \Illuminate\Routing\Middleware\SubstituteBindings::class, ], diff --git a/app/Http/Middleware/CustomCors.php b/app/Http/Middleware/CustomCors.php new file mode 100644 index 0000000..7f8b57a --- /dev/null +++ b/app/Http/Middleware/CustomCors.php @@ -0,0 +1,36 @@ +getMethod() === 'OPTIONS') { + $response->headers->set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE, PATCH'); + $response->headers->set('Access-Control-Allow-Headers', 'Content-Type, X-API-Version, X-Client-ID, Authorization, X-Requested-With, Accept'); + $response->headers->set('Access-Control-Max-Age', '86400'); + } + + // 允許所有域名 + $response->headers->set('Access-Control-Allow-Origin', '*'); + + // 當允許所有域名時,不能設置 credentials + // $response->headers->set('Access-Control-Allow-Credentials', 'true'); + + return $response; + } +} diff --git a/config/cors.php b/config/cors.php new file mode 100644 index 0000000..92e3c6c --- /dev/null +++ b/config/cors.php @@ -0,0 +1,19 @@ + ['api/*'], + 'allowed_methods' => ['*'], + 'allowed_origins' => ['*'], + 'allowed_origins_patterns' => [], + 'allowed_headers' => [ + 'Content-Type', + 'X-Requested-With', + 'Authorization', + 'X-API-Version', + 'X-Client-ID', + 'Accept', + ], + 'exposed_headers' => [], + 'max_age' => 0, + 'supports_credentials' => true, +]; diff --git a/doc/llmapiv2.html b/doc/llmapiv2.html deleted file mode 100644 index 587bc50..0000000 --- a/doc/llmapiv2.html +++ /dev/null @@ -1,339 +0,0 @@ - - -
- - -This document describes the API endpoints for the LLM service.
- -https://llmbackend.local:7890
-
- /api/admin/login/api/auth/tokenAll API requests must include:
-Content-Type: application/json
-Accept: application/json
-X-API-Version: 1.0
-X-Client-ID: your-client-id
-
- Root endpoint that returns the API status.
-{
- "success": true,
- "data": {
- "status": "ok",
- "version": "1.0"
- }
-}
- Simple test endpoint to verify API connectivity.
-Exchange auth token for an access token.
-{
- "auth_token": "64-character-auth-token"
-}
- {
- "success": true,
- "data": {
- "access_token": "generated-access-token",
- "expires_in": 3600
- }
-}
- Make a request to the LLM service.
-Authorization: Bearer {access_token}
- {
- "prompt": "Your prompt text here",
- "max_tokens": 100,
- "temperature": 0.7,
- "top_p": 1,
- "frequency_penalty": 0,
- "presence_penalty": 0
-}
- {
- "success": true,
- "data": {
- "response": "LLM generated response"
- }
-}
- {
- "email": "your-email",
- "password": "your-password"
-}
- {
- "success": true,
- "data": {
- "token": "admin-bearer-token",
- "admin": {
- "id": 1,
- "email": "your-email"
- }
- }
-}
- Authorization: Bearer {admin_token}
- Authorization: Bearer {admin_token}
- {
- "current_password": "current-password",
- "new_password": "new-password",
- "new_password_confirmation": "new-password"
-}
- Authorization: Bearer {admin_token}
- {
- "success": true,
- "data": {
- "items": [
- {
- "id": 1,
- "name": "Client Name",
- "llm_provider_id": 1,
- "created_at": "2024-12-05T00:00:00Z"
- }
- ]
- }
-}
- Authorization: Bearer {admin_token}
- {
- "name": "New Client Name",
- "llm_provider_id": 1
-}
- Authorization: Bearer {admin_token}
- Authorization: Bearer {admin_token}
- {
- "name": "Updated Client Name",
- "llm_provider_id": 1
-}
- Authorization: Bearer {admin_token}
- Authorization: Bearer {admin_token}
- {
- "success": true,
- "data": {
- "client_id": 1,
- "auth_token": "generated-auth-token",
- "created_at": "2024-12-05T00:00:00Z"
- }
-}
- Authorization: Bearer {admin_token}
- {
- "success": true,
- "data": {
- "items": [
- {
- "id": 1,
- "name": "OpenAI",
- "service_name": "openai",
- "api_url": "https://api.openai.com/v1",
- "status": "active",
- "created_at": "2024-12-05T00:00:00Z"
- }
- ]
- }
-}
- Authorization: Bearer {admin_token}
- {
- "name": "OpenAI",
- "service_name": "openai",
- "api_url": "https://api.openai.com/v1",
- "api_token": "your-api-token",
- "status": "active"
-}
- Authorization: Bearer {admin_token}
- Authorization: Bearer {admin_token}
- {
- "name": "Updated OpenAI",
- "service_name": "openai",
- "api_url": "https://api.openai.com/v1",
- "api_token": "your-api-token",
- "status": "active"
-}
- Authorization: Bearer {admin_token}
- All endpoints return standardized error responses:
-{
- "success": false,
- "error": "error_code",
- "message": "Error message",
- "errors": {
- "field": ["Error details"]
- }
-}
-
- All successful responses follow the format:
-{
- "success": true,
- "data": {
- // Response data
- }
-}
-
-