Skip to content

Cors Issue #1040

@noxsii

Description

@noxsii
  • Lumen Version: 6.3.3
  • Laravel Version: 6.0
  • PHP Version: 7.3
  • Database Driver & Version: mysql

Description:

CORS Policy:
Have the problem that I permanently have the error with Cors. I've made several attempts to fix this. But unfortunately without success. I try to add the Middleware global with:

$app->routeMiddleware([ App\Http\Middleware\Cors::class, ..... ]);

The Middleware:

`namespace App\Http\Middleware;
use Closure;

class Cors
{
protected $settings = array(
'origin' => '*', // Wide Open!
'allowMethods' => 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
);

public function handle($request, Closure $next)
{
    $headers = [
        'Access-Control-Allow-Origin'      => '*',
        'Access-Control-Allow-Methods'     => 'POST, GET, OPTIONS, PUT, DELETE',
        'Access-Control-Allow-Credentials' => 'true',
        'Access-Control-Max-Age'           => '86400',
        'Access-Control-Allow-Headers'     => 'Content-Type, Authorization, X-Requested-With'
    ];

    if ($request->isMethod('OPTIONS'))
    {
        return response()->json('{"method":"OPTIONS"}', 200, $headers);
    }

    $response = $next($request);
    foreach($headers as $key => $value)
    {
        $response->header($key, $value);
    }

    return $response;
}

}`

I add the Header in the the routes/web,php with:

header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE'); header('Access-Control-Allow-Headers: Content-Type, X-Auth-Token, Origin, Authorization');

unfortunately none of the solutions led to success. Someone a solution or a suggestion?

Work with vue.js local :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions