user1518071
user1518071

Reputation: 59

Laravel and angularjs getting 405 Method not allowed error

I have installed laravel homestead, and it works properly I am able communicate with the backend and get a respons using the API. Now I also installed angularjs it seems to work also, but what is not working is to POST or GET to the laravel API from the Angular app as frontend. I am getting the following errors in firefox inspector Network:

405 Method Not Allowed
request headers 
Host: demo.app:8000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:37.0) Gecko/20100101 Firefox/37.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Origin: http://frontend.app:8000
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

Response Header
Cache-Control: no-cache
Connection: keep-alive
Content-Type: text/html; charset=UTF-8
Date: Fri, 01 May 2015 02:28:25 GMT
Server: nginx/1.6.2
Set-Cookie: laravel_session=
Transfer-Encoding: chunked

and in the console log:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://demo.app:8000/myUrl This can be fixed by moving the resource to the same domain or enabling CORS.

I am not really sure why they are not communicating I followed all the instructions properly plus they are working fine independently (Laravel API, and Angularjs for frontend). Any thoughts and help will be appreciated

Upvotes: 0

Views: 1879

Answers (1)

DevManny
DevManny

Reputation: 1326

you need to add / replace these lines in your /app/filters.php

App::before(function ($request) {
    header("Access-Control-Allow-Origin: *");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
});

Upvotes: 2

Related Questions