Skip to content
This repository was archived by the owner on Feb 14, 2023. It is now read-only.

Commit 20b41ba

Browse files
mfnspawnia
authored andcommitted
Add security related options to config to disable in production and/or use a custom route (#4)
1 parent 5effa1c commit 20b41ba

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,28 @@ Easily integrate [GraphQL Playground](https://github.com/prismagraphql/graphql-p
1616

1717
If you are using Laravel < 5.4, add the service provider to your `config/app.php`
1818

19-
````php
19+
```php
2020
'providers' => [
2121
// Other providers...
2222
MLL\\GraphQLPlayground\\GraphQLPlaygroundServiceProvider::class,
2323
]
24-
````
24+
```
2525

2626
You may publish the configuration and/or the views:
2727

28-
php artisan vendor:publish
28+
php artisan vendor:publish --provider="MLL\GraphQLPlayground\GraphQLPlaygroundServiceProvider"
2929

3030
## Usage
3131

3232
By default, the playground is reachable at `/graphql-playground`
3333

3434
It assumes a running GraphQL endpoint at `/graphql`. You can enter another URL in the
3535
UI or change the default setting in the configuration file.
36+
37+
## Security
38+
39+
If you do not want to enable the GraphQL playground in production, you can disable it in the config file.
40+
The easiest way is to set the environment variable `GRAPHQL_PLAYGROUND_ENABLED=false`
41+
42+
If you want to add custom middleware to protect the route to the GraphQL playground, you can
43+
add it in the configuration file.

config/graphql-playground.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
return [
44
// Route for the frontend
55
'route' => 'graphql-playground',
6-
6+
7+
// Which middleware to apply, if any
8+
'middleware' => [
9+
// 'web',
10+
],
11+
712
// Route for the GraphQL endpoint
813
'endpoint' => 'graphql',
14+
15+
// Control if the playground is accessible at all
16+
// This allows you to disable it completely in production
17+
'enabled' => env('GRAPHQL_PLAYGROUND_ENABLED', true),
918
];

src/GraphQLPlaygroundServiceProvider.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@ public function boot()
2626
self::VIEW_PATH => resource_path('views/vendor/graphql-playground'),
2727
], 'views');
2828

29-
\Route::get(config('graphql-playground.route'), function () {
30-
return view('graphql-playground::index');
31-
});
29+
if (!config('graphql-playground.enabled', true)) {
30+
return;
31+
}
32+
33+
\Route::get(config('graphql-playground.route'), [
34+
'middleware' => config('graphql-playground.middleware', ''),
35+
'as' => 'graphql-playgroundcontroller',
36+
'uses' => function () {
37+
return view('graphql-playground::index');
38+
},
39+
]);
3240
}
3341

3442
/**

0 commit comments

Comments
 (0)