mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-22 04:58:01 +01:00
Using CORS middleware for API requests from supported origins
This commit is contained in:
parent
f7bc4f0565
commit
780217183e
6 changed files with 744 additions and 429 deletions
|
@ -57,7 +57,6 @@ class Kernel extends HttpKernel
|
||||||
'can' => \Poniverse\Ponyfm\Http\Middleware\Authorize::class,
|
'can' => \Poniverse\Ponyfm\Http\Middleware\Authorize::class,
|
||||||
'json-exceptions' => \Poniverse\Ponyfm\Http\Middleware\JsonExceptions::class,
|
'json-exceptions' => \Poniverse\Ponyfm\Http\Middleware\JsonExceptions::class,
|
||||||
'guest' => \Poniverse\Ponyfm\Http\Middleware\RedirectIfAuthenticated::class,
|
'guest' => \Poniverse\Ponyfm\Http\Middleware\RedirectIfAuthenticated::class,
|
||||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class
|
||||||
'cors' => \Poniverse\Ponyfm\Http\Middleware\Cors::class,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Poniverse\Ponyfm\Http\Middleware;
|
|
||||||
|
|
||||||
use App;
|
|
||||||
|
|
||||||
class Cors {
|
|
||||||
public function handle($request, $next)
|
|
||||||
{
|
|
||||||
if (App::environment('local', 'staging')) {
|
|
||||||
return $next($request)
|
|
||||||
->header('Access-Control-Allow-Origin', '*')
|
|
||||||
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
||||||
} else {
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -26,7 +26,8 @@
|
||||||
"graham-campbell/exceptions": "^9.1",
|
"graham-campbell/exceptions": "^9.1",
|
||||||
"minishlink/web-push": "^1.0",
|
"minishlink/web-push": "^1.0",
|
||||||
"alsofronie/eloquent-uuid": "^1.0",
|
"alsofronie/eloquent-uuid": "^1.0",
|
||||||
"poniverse/api": "dev-rewrite"
|
"poniverse/api": "dev-rewrite",
|
||||||
|
"barryvdh/laravel-cors": "^0.8.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fzaninotto/faker": "~1.4",
|
"fzaninotto/faker": "~1.4",
|
||||||
|
|
1126
composer.lock
generated
1126
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -168,8 +168,8 @@ return [
|
||||||
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
|
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
|
||||||
Cviebrock\LaravelElasticsearch\ServiceProvider::class,
|
Cviebrock\LaravelElasticsearch\ServiceProvider::class,
|
||||||
GrahamCampbell\Exceptions\ExceptionsServiceProvider::class,
|
GrahamCampbell\Exceptions\ExceptionsServiceProvider::class,
|
||||||
Poniverse\Lib\PoniverseServiceProvider::class
|
Poniverse\Lib\PoniverseServiceProvider::class,
|
||||||
|
Barryvdh\Cors\ServiceProvider::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
19
config/cors.php
Normal file
19
config/cors.php
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
return [
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Laravel CORS
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| allowedOrigins, allowedHeaders and allowedMethods can be set to array('*')
|
||||||
|
| to accept any value.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
'supportsCredentials' => true,
|
||||||
|
'allowedOrigins' => ['localhost:3000', 'pony.fm', 'stage.pony.fm'],
|
||||||
|
'allowedHeaders' => ['*'],
|
||||||
|
'allowedMethods' => ['*'],
|
||||||
|
'exposedHeaders' => [],
|
||||||
|
'maxAge' => 0,
|
||||||
|
'hosts' => [],
|
||||||
|
];
|
Loading…
Reference in a new issue