681557b5 by Jeff Balicki

w

1 parent d0e22954
1 <?php 1 <?php
2 namespace App\Http\Middleware;
3
4 use Closure; 2 use Closure;
5 3
6 class Cors 4 class CORS {
7 {
8 5
9 /** 6 /**
10 * Handle an incoming request. 7 * Handle an incoming request.
11 * 8 *
12 * @param \Illuminate\Http\Request $request 9 * @param \Illuminate\Http\Request $request
13 * @param \Closure $next 10 * @param \Closure $next
14 *
15 * @return mixed 11 * @return mixed
16 */ 12 */
17 public function handle($request, Closure $next) 13 public function handle($request, Closure $next)
18 { 14 {
19 15
20 return $next($request)->header('Access-Control-Allow-Origin' , 'http://contact.gotenzing.com') 16 header("Access-Control-Allow-Origin: *");
21 ->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE') 17
22 ->header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With') 18 // ALLOW OPTIONS METHOD
23 ->header('Content-type: text/html'); 19 $headers = [
24 ; 20 'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
25 } 21 'Access-Control-Allow-Headers'=> 'Content-Type, X-Auth-Token, Origin'
22 ];
23 if($request->getMethod() == "OPTIONS") {
24 // The client-side application can set only headers allowed in Access-Control-Allow-Headers
25 return Response::make('OK', 200, $headers);
26 }
27
28 $response = $next($request);
29 foreach($headers as $key => $value)
30 $response->header($key, $value);
31 return $response;
26 } 32 }
33
34 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -30,7 +30,7 @@ Route::group(array('prefix' => 'api/v1'), function($json) ...@@ -30,7 +30,7 @@ Route::group(array('prefix' => 'api/v1'), function($json)
30 30
31 }); 31 });
32 32
33 Route::any('api/update', ['middleware' => 'cors', 'uses' => 'ApiController@update']); 33 Route::any('api/update', array('middleware' => 'cors', 'uses' => 'ApiController@update'));
34 34
35 Route::any('fileentry/postUpload', 'FileEntryController@postUpload'); 35 Route::any('fileentry/postUpload', 'FileEntryController@postUpload');
36 36
......
1 <?php 1 <?php
2 2
3 // allow origin
4 header('Access-Control-Allow-Origin: *');
5 // add any additional headers you need to support here
6 header('Access-Control-Allow-Headers: Origin, Content-Type');
7 3
8 4
9 /* 5 /*
......