I have the following code in my AngularJS4 project:
const url = "http://localhost:4151/test";
this.http.get(url).toPromise()
.then((r) => {
console.log("SUCCESS", r);
})
.catch((e) => {
console.error("ERR", e);
});
The URL works fine when typed in the browser bar, and I have enabled CORS headers on the server side:
// Allow CORS
this.app.use(function(req: Request, res: Response, next: Function) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
Whenever I make a call to the server from my Angular application, it returns a 404 - Not Found error.
Any ideas how to fix this?
Thanks.