1

i'm using nuxt/axios with laravel as my backend. in my responses from laravel i send a custom header named _msg but i cant access it. in my console.log(response) i get only this:

enter image description here

but in my brower network i get the header:

enter image description here

how can i access it?

UPDATED

added this to my laravel middleware: this is an example if request is from manager and admin

<?php

namespace App\Http\Middleware;

use Closure;
use App\Traits\UtilsTrait;

class ManagerPlus
{
    use UtilsTrait;
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
//        return $next($request);
        if($this->isMoreManager()){
            $request->panelType = $this->addPanelType();
            $response = $next($request);

            $response->headers->set('Access-Control-Expose-Headers', 'Content-Disposition');
            return $response;
        }
        return $this->permissionDenied();
    }
}


UPDATE AFTER EXPOSE:

i did as told with my laravel/fruitcake setting and middleware and this is my new header that i get from axios. but still not getting my _msg

enter image description here

Mojtaba Barari
  • 1,127
  • 1
  • 15
  • 49
  • Maybe is CORS thing https://stackoverflow.com/a/37931084/181766 – jjchiw Jul 29 '20 at 11:46
  • i have read this before but didn't know what to do exactly!! is it something that must be config on `Laravel` or on `Nuxt` ? btw i had `cors` problems and installed a package on my laravel – Mojtaba Barari Jul 29 '20 at 12:58
  • The configuration should be made int the server side (lavarel). It seems in laravel you need to create a Middleware https://github.com/fruitcake/laravel-cors/issues/308#issuecomment-490969761 – jjchiw Jul 29 '20 at 14:08
  • @jjchiw i exposed my custom header in laravel middleware but still dont get on my `nuxt/axios` . shouldn't do anything on my nuxt? – Mojtaba Barari Aug 05 '20 at 12:12
  • Can you update the question, with the changes – jjchiw Aug 05 '20 at 16:57
  • @jjchiw updated with my backend middleware. it is for requests from manager and superadmin. i have added the expose to other request too!! – Mojtaba Barari Aug 06 '20 at 10:48
  • did you added `Setting exposedHeader = ['_msg'] in cors.php` and if you could put an image of the `ResponseHeaders` – jjchiw Aug 06 '20 at 11:07
  • @jjchiw I didn't get your first question! What is cors.php? For cors I used a package, and added that in my kernel. The image of ResponseHeaders is up there in my post. Can you fully explain in answer. Tanx a lot – Mojtaba Barari Aug 07 '20 at 18:21

1 Answers1

1

What I think you need to do is:

if you are using the package https://github.com/fruitcake/laravel-cors you will have config/cors.php and there is where you should add

'exposed_headers' => ['_msg'],

and you have to create the middleware as it's explained in the issue https://github.com/fruitcake/laravel-cors/issues/308#issuecomment-490969761

$response->headers->set('Access-Control-Expose-Headers', '_msg');

I hope it works

jjchiw
  • 4,375
  • 1
  • 29
  • 30
  • Yeah im using `fruitcak` , i set the `exposed_headers' => ['_msg']` in my `cors.php` and as u see in my issue update i use set header in my middleware too. still not getting the `_msg` header. i get it in browser network, i get it in postman, not in nuxt!! i think something is wrong with my axios or nuxt config – Mojtaba Barari Aug 10 '20 at 11:35
  • did you solve it? is it because in http headers underscore in nginx need an extra configuration? https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#missing-disappearing-http-headers forgot about this.... – jjchiw Aug 10 '20 at 13:38
  • no, not solved yet!! T_T . my back is not on server. it's on another laptop with `Windows OS` that is shared with me and is acting as host. – Mojtaba Barari Aug 10 '20 at 13:46
  • 1
    `$response->headers->set('Access-Control-Expose-Headers', '_msg');` I thinks this is the line needed in the middleware – jjchiw Aug 10 '20 at 14:28