【发布时间】:2018-10-27 18:43:46
【问题描述】:
我从 Angular 5 开始,我想显示来自 JAX-RS API 的城市列表,然后我收到以下错误:
http://localhost:4200/api/ 的 Http 失败响应:404 Not Found
在这里您可以找到我使用的文件:
ville.service.ts
import {Injectable} from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Ville } from '../models/ville.model';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
@Injectable()
export class VilleService {
constructor(private http:HttpClient) {}
private userUrl = '/api/';
public getVilles() {
return this.http.get<Ville[]>(this.userUrl);
}
public deleteVille(ville) {
return this.http.delete(this.userUrl + "/"+ ville.idVille);
}
public createVille(ville) {
return this.http.post<Ville>(this.userUrl, ville);
}
}
proxy.config.json
{
"/api/*": {
"target": "http://localhost:8080/QuickDep/Compagne",
"secure": false
}
}
在 package.json
"start": "ng serve --proxy-config proxy.config.json",
【问题讨论】: