Skip to content

Commit 2d04062

Browse files
committed
Implemented laravel-cors for api routes
1 parent 0b2aed8 commit 2d04062

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

app/Http/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Kernel extends HttpKernel
3333
],
3434

3535
'api' => [
36+
\Barryvdh\Cors\HandleCors::class,
3637
'throttle:60,1',
3738
'bindings',
3839
],

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"type": "project",
77
"require": {
88
"php": ">=5.6.4",
9+
"barryvdh/laravel-cors": "^0.9.3",
910
"laravel/framework": "5.3.*"
1011
},
1112
"require-dev": {

composer.lock

Lines changed: 64 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
* Package Service Providers...
168168
*/
169169
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
170+
Barryvdh\Cors\ServiceProvider::class,
170171

171172
/*
172173
* Application Service Providers...

config/cors.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Laravel CORS
8+
|--------------------------------------------------------------------------
9+
|
10+
| allowedOrigins, allowedHeaders and allowedMethods can be set to array('*')
11+
| to accept any value.
12+
|
13+
*/
14+
15+
'supportsCredentials' => false,
16+
'allowedOrigins' => ['*'],
17+
'allowedHeaders' => ['*'],
18+
'allowedMethods' => ['*'],
19+
'exposedHeaders' => [],
20+
'maxAge' => 0,
21+
22+
];

routes/api.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<?php
22

33
Route::get('/endereco/{userId}', 'ApiController@address')->middleware('api');
4-

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy