javascript - 如何解决来自后端层的 Angular 504 错误响应
问题描述
我的本地主机(http)上有角度应用程序,本地主机(https)上有一个弹簧启动应用程序。代理已配置为 Angular 以访问 Spring Boot API,但在从 Angular 调用后端 api 时出现 504 错误。我还尝试使用 proxy.conf.json 创建后端层的代理,但没有奏效。感谢你的帮助
proxy-config.js-->
const fs = require("fs");
const PROXY_CONFIG = {
"/api/*": {
changeOrigin: true,
secure: false,
target: {
host: "127.0.0.1:8080",
passphrase: 'xxxx',
pfx: fs.readFileSync('./applicationcert.pfx'),
protocol: "https:"
}
}
};
module.exports = PROXY_CONFIG;
Sercice.js-->
this.httpClient.request('GET', '/api/v1', options).subscribe(data => {
console.log(data)
},error => {
console.log(error);
},
() => {
console.log("Subscribed Else");
});
package.json-->
"start": "ng serve --host 127.0.0.1 --proxy-config proxy-config.js",
解决方案
在我的角度项目中,我以这种方式集成了 proxy.conf:
在 angular.json 上
"serve": {
....
"options": {
"proxyConfig": "src/proxy.conf.json",
},
和我的 proxy.conf.json
{
"/path/to/api/*": { // with * i can intercept all the api that start wit this url
"target": "http://localhost:8881", //this is the target where angular redirect api calls
"secure": false,
"logLevel": "debug"
},
在这里您可以找到更多信息
推荐阅读
- c# - 如何找到尝试访问不存在的数据库列的代码?
- typescript - 赛普拉斯浏览器状态保持登录状态。如何阻止这种情况发生?
- javascript - 页面刷新后如何保留前置图像?
- multithreading - 每个 OpenGL 管道状态有多少个线程?
- javascript - JavaScript编码面试第一个重复数组中的字符不适用于null
- javascript - ValidateAntiForgeryToken 不适用于 ASP.NET Core 中的 Axios POST
- javascript - 为什么会在未经允许的情况下关闭弹出窗口?谷歌 Auth2
- c# - RavenDB - 多对多关系文档上的索引是否比集合属性上的索引更有效?
- r - 区分外部变量和数据表中的列
- ios - xamarin iOS 使用共享项目与 HttpClient 不工作