“http://localhost:4200/api/ 的 Http 失败响应:404 未找到”Angular 5

问题描述 投票:0回答:1

我从 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",
    
angular angular5
1个回答
0
投票
尝试:

{ "/api": { "target": "http://localhost:8080/QuickDep", "secure": false, "changeOrigin": true } }
    
© www.soinside.com 2019 - 2024. All rights reserved.