Skip to content

Commit 20b52fa

Browse files
committed
more documentation
1 parent 8488190 commit 20b52fa

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

.env.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ CLOCKWORK_ENABLE=false
3030
# Always disabled on production environment.
3131
# APP_DEBUG_LATENCY=0
3232

33+
# All API requests to have the header "content-type: application/json"
34+
# or "content-type: multipart/form-data" depending on the type.
35+
#
36+
# If you want to disable this requirement, set this to false.
37+
#
38+
# This requirement prevents the use of the API from the API documentation page.
39+
REQUIRE_CONTENT_TYPE_ENABLED=true
40+
3341
# enable s3 bucket (required in addition to needing AWS_ACCESS_KEY_ID)
3442
# S3_ENABLED=true
3543

@@ -208,3 +216,4 @@ VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
208216
###################################################################
209217
# VITE_LOCAL_DEV=true
210218
# VITE_HTTP_PROXY_TARGET=http://localhost:8000
219+

app/Http/Middleware/ContentType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class ContentType
4040
*/
4141
public function handle(Request $request, \Closure $next, string $contentType): mixed
4242
{
43+
// Skip if check is disabled
44+
if (config('features.require-content-type') === false) {
45+
return $next($request);
46+
}
47+
4348
if ($contentType === self::JSON) {
4449
if (!$request->isJson()) {
4550
throw new UnexpectedContentType(self::JSON);

config/features.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,14 @@
9090
|--------------------------------------------------------------------------
9191
*/
9292
'latency' => env('APP_ENV', 'production') === 'production' ? 0 : (int) env('APP_DEBUG_LATENCY', 0),
93+
94+
/*
95+
|--------------------------------------------------------------------------
96+
| Require the API requests to have the header "content-type: application/json"
97+
| or "content-type: multipart/form-data" depending on the type.
98+
|
99+
| Note that this prevents the use of the API from the API documentation page.
100+
|--------------------------------------------------------------------------
101+
*/
102+
'require-content-type' => (bool) env('REQUIRE_CONTENT_TYPE_ENABLED', true),
93103
];

config/scramble.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
/*
3030
* Description rendered on the home page of the API documentation (`/docs/api`).
3131
*/
32-
'description' => '',
32+
'description' => '**NOTE:** In order to use the API in this page, you will need to disable the _"content-type"_ middleware.<br>
33+
This is done by setting your `REQUIRE_CONTENT_TYPE_ENABLED=false` in your `.env`.<br>
34+
After testing, we recommend setting back this value to `true` and adding the content-type header to your requests.',
3335
],
3436

3537
/*

0 commit comments

Comments
 (0)