Laravel API blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource

I’ve laravel rest API application that connects with the Vue js frontend.

Rest API endpoint domain is dev.mydomain.com and images are host in s3 bucket that subdomain is dev-assest.mydomain.com

When the application loads the page with an image it gives below error. However, image is losing when checking the image URL

Access to fetch at ‘https:// dev-assest.mydomain.com/images/profiles/profile_5bb3d976f12.jpeg’ from origin ‘https://ift.tt/2y2OlIp’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

In Laraval backed added cors as below. Cors.php

namespace AppHttpMiddleware;

use Closure;

class Cors
{
/**
* Handle an incoming request.
*
* @param IlluminateHttpRequest $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
->header('Access-Control-Allow-Headers',' Origin, Content-Type, Accept, Authorization, X-Request-With')
->header('Access-Control-Allow-Credentials',' true');
}
}

And Kernal.php

 protected $routeMiddleware = [
'cors' => AppHttpMiddlewareCors::class,
];

Vue frontend also added below in vue.config.js file

devServer: {
headers: { 'Access-Control-Allow-Origin': '*' }
}

Is there any other way to fix this issue?

from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/2K133ZH
via IFTTT

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.