When I navigate to a diffrerent page in my project, the console shows a 404 error with wrong url. Here's how it looks like:
while it should look like:
As I target example.com
api, I specified nowhere in the project to use localhost:4220
api.
Here is my environment.ts:
export const environment = {
production: false,
baseUrl: 'example.com/',
apiUrl: 'example.com/api/'
};
And here is how I use the service:
export class CustomersComponent implements OnInit {
customers: any;
constructor(private http: HttpClient) { }
ngOnInit() {
const token = localStorage.getItem('jwt');
this.http.get(environment.apiUrl + 'customers', {
headers: new HttpHeaders({
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json'
})
}).subscribe(response => {
this.customers = response;
}, err => {
console.log(err);
});
}
}
if I remove environment.apiUrl +
from the code above, I get
Request URL: http://localhost:4220/customers
so from where comes the part "localhost:4420/" and where it is concatenated ?
Try to changes env. file with https
protocol, like below -
export const environment = {
production: false,
baseUrl: 'https://example.com/',
apiUrl: 'https://example.com/api/'
};