Compare commits
No commits in common. "44c322a506b109b85acf1ee748b69868ecb46329" and "15ad765e2c76cbd06ba6262074922acfb80b4267" have entirely different histories.
44c322a506
...
15ad765e2c
4 changed files with 13 additions and 56 deletions
|
|
@ -40,7 +40,6 @@ class Kernel extends HttpKernel
|
||||||
|
|
||||||
'api' => [
|
'api' => [
|
||||||
\App\Http\Middleware\ValidateHeaders::class,
|
\App\Http\Middleware\ValidateHeaders::class,
|
||||||
\App\Http\Middleware\CustomCors::class,
|
|
||||||
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
|
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
|
||||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Closure;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
|
|
||||||
class CustomCors
|
|
||||||
{
|
|
||||||
public function handle(Request $request, Closure $next): Response
|
|
||||||
{
|
|
||||||
$response = $next($request);
|
|
||||||
|
|
||||||
if (!$response instanceof Response) {
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 處理 OPTIONS 請求
|
|
||||||
if ($request->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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
'paths' => ['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,
|
|
||||||
];
|
|
||||||
|
|
@ -81,6 +81,19 @@ <h2>Endpoints</h2>
|
||||||
|
|
||||||
<h3>Public Routes</h3>
|
<h3>Public Routes</h3>
|
||||||
|
|
||||||
|
<div class="endpoint">
|
||||||
|
<h4><span class="method get">GET</span> /</h4>
|
||||||
|
<p>Root endpoint that returns the API status.</p>
|
||||||
|
<h5>Response:</h5>
|
||||||
|
<pre><code>{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"status": "ok",
|
||||||
|
"version": "1.0"
|
||||||
|
}
|
||||||
|
}</code></pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="endpoint">
|
<div class="endpoint">
|
||||||
<h4><span class="method get">GET</span> /api/test</h4>
|
<h4><span class="method get">GET</span> /api/test</h4>
|
||||||
<p>Simple test endpoint to verify API connectivity.</p>
|
<p>Simple test endpoint to verify API connectivity.</p>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue