angular - 在 localhost:4200 中找不到 404
问题描述
我正在尝试将数据从“ http://localhost:8082/api/kanchiwork/ ”传递到“ http://localhost:4200/ ”。我的 proxy.config.json 文件是:
{
"context": [
"/api/**"
],
"pathRewrite": {
"^/api": ""
},
"ws": false,
"target": "http://localhost:8082",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
]
我的服务文件如下。
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class PeopleService {
constructor(private http:HttpClient) { }
fetchPeople(): Observable<Object>{
return this.http.get('/api/kanchiwork/');
//return this.http.get('assets/response.json');
};
}
. 当我尝试传递值时,在控制台中收到消息为“GET localhost:4200/api/kanchiwork 404(未找到)”。
解决方案
{
"/api": {
"target": "http://localhost:8082",
"secure": false
},
"logLevel": "debug"
}
您可以运行 ng serve --proxy-config proxy.conf.json
否则你可以更新你的 package.json 脚本属性:
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
}
然后运行 npm start
注意:如果您更改 proxy.conf 中的任何内容,您需要重新运行(ng serve/npm start)您的应用程序以查看实际更改。
推荐阅读
- amazon-web-services - 如何从 aws cloudwatch 获取指标数据到 csv
- java - 如何使用 gradle + spring boot 1.5 构建子模块的可执行 jar
- laravel - Laravel 视图错误
- javascript - Jquery first() 不工作
- javascript - Javascript程序产生未定义(递归)
- postgresql - 命令中的 Postgres 语法错误与文档一致
- rethinkdb - 当我向 RethinkDB 查询添加索引时,为什么会得到结果?
- php - WordPress 站点中的警告消息。“参数 1 不是数组”网站名称“RealLifeCBD.com”
- c# - 如何动态检查 if 语句
- laravel - 错误 App\Http\Requests\AddUserRequest::fails 不存在