I'm using angular 4.0.0
instaled with angular-cli
to create a simple application, but I keep getting a 404 File not found
error when trying to call a PHP file.
Basically I'm starting the Angular using ng serve
, which runs the application on http://localhost:4000
and I also have WAMP running, so I can use the php file to connect to a phpmyadmin and get data from a backend database.
I used to do it with Angular 1.5+ and it worked fine, but now I keep getting this error:
http://localhost:4000/api/server 404 (Not Found)
This is my folder structure:
root
- src
--api
--app
--assets
// etc..
If I try to call other url, for example, one that is online on an actual server, then it works as expected.
This is the file responsable for the http calls:
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';
@Injectable()
export class ApiService {
constructor(
private http: Http,
) { }
apiGet() {
return this.http.get(
'./api/server'
).map(response => response.json()).do(data => {
// -
}).catch(this.handleErrors);
}
apiPost(info: object) {
const headers = new Headers();
headers.append('Access-Control-Allow-Origin', '*');
return this.http.post(
'./api/server',
JSON.stringify(info),
{ headers }
).map(response => response.json()).do(data => {
console.log( 'Response: ', data )
// -
}).catch(this.handleErrors);
}
handleErrors(error: Response) {
console.log( 'Error: ', error )
return Observable.throw(error);
}
}
What am I doing wrong in here?