0

I have an angular project which is my root website and having a Laravel project in the backend folder in public_html. I have two types of routes, /backend/api/** is my api routes which I want to redirect to /404 in angular project when user want to access directly in the browser but want to access via httpclient module in angular and I have /backend/admin/** which is my admin routes and I want to stay untouched and can be accessed via the browser. My problem is the ** route in the angular overlap all the laravel routes and redirects to /404. what is the best solution. should I change .htaccess file or what? would you please help me?

1 Answers1

0

i don't know about angular so i took ref from this Adding a HTTP header to the Angular HttpClient doesn't send the header, why?

in angular

let headers = new HttpHeaders();
headers = headers.set('from', 'api');

then create a middleware

public function handle($request, Closure $next)
{
    if($request->header('from') != 'api'){
        return redirect('/'); // replace this with your url
    }
    return $next($request);
}

NOTE this is not exact solution but it is an idea

Kamlesh Paul
  • 11,778
  • 2
  • 20
  • 33