0

I am using AngularJS as front-end and Laravel as back-end for handling API requests.

Also, Laravel constitute the administration panel for the website.

In order to overcome the CORS related challenges, I've added the following code in routes.php of Laravel:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Origin, Content-Type');
header('Access-Control-Allow-Methods', 'GET,POST, OPTIONS');
header('Access-Control-Allow-Credentials', 'true');
header('Access-Control-Allow-Headers', 'accept, content-type, x-xsrf-token, x-csrf-token');

But when we load administration panel it shows internal server error (GoDaddy server).

If we remove this the administration panel works fine, but the AngularJS part faces problem.

The API requests are blocked by the server.

What am I doing wrong and how can I resolve this issue?

5
  • Are you sure those are the only headers in the request? Commented Jan 29, 2017 at 16:24
  • Does the administration panel loads with no error without your header() edits? Commented Jan 29, 2017 at 16:32
  • I doubt very much you're meant to make direct calls to header. Have a look at en.vedovelli.com.br/2015/web-development/… Commented Jan 30, 2017 at 3:48
  • yes I am sure. The next lines are for handling get and post requests. Route::get('/', function () { return view('pages.login'); }); Route::get('user1', 'User@userlist')->name('user1'); Commented Jan 30, 2017 at 3:57
  • yes administration panel loads with no error without this header. Commented Jan 30, 2017 at 3:58

1 Answer 1

1

You could do this outside of Laravel, and set the headers instead with mod_headers:

http://httpd.apache.org/docs/current/mod/mod_headers.html#examples

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.