我们已经为运行在4200上的Angular 8应用程序实现了代理,但运行在Tomcat 8080上的后端api不起作用

我们已经为运行在4200上的Angular 8应用程序实现了代理,但运行在Tomcat 8080上的后端api不起作用,angular,proxy,Angular,Proxy,我们已经为运行在:4200上的Angular 8应用程序实现了代理,以支持运行在Tomcat 8080上的后端api。它不起作用了 使用如下所示的角度版本 角度CLI:8.3.20 节点:12.13.1 操作系统:win32 x64 角度:8.2.14 let me mention changes we did. proxy.conf.json { "/student/allstudent": { "target": "http://loca

我们已经为运行在
:4200
上的Angular 8应用程序实现了代理,以支持运行在
Tomcat 8080
上的后端api。它不起作用了

使用如下所示的角度版本 角度CLI:8.3.20 节点:12.13.1 操作系统:win32 x64 角度:8.2.14

    let me mention changes we did.
    proxy.conf.json 
    {
      "/student/allstudent": {
        "target": "http://localhost:8080",
        "secure": false,
        "pathRewrite": {
          "^/student/allstudent": ""
        },
        "logLevel": "debug",
        "changeOrigin": true
      }
    }

    in `package.json` we added this line "start": "ng serve --proxy-config proxy.conf.json"
    In `angular.json` file we have added below proxy config under serve.
    "options": {
                "browserTarget": "PricingWorkBench-ui:build",
                "proxyConfig": "proxy.conf.json"
              },

    service method look like this in Angular 
    public getStudentDetails(): Observable<any> {
        return this.http.get("http://localhost:8083/student/allstudent").
          pipe(
            map((data: any) => {
             return data;
            })
          )
      }

如果您的端点在
http://localhost:8083/student/allstudent

您的proxy.conf.json应该是:

{
    "/student/allstudent": {
        "target": "http://localhost:8083",
        "secure": false,
        "logLevel": "debug",
        "changeOrigin": true
    }
}
您的方法如下所示:

public getStudentDetails(): Observable<any> {
    return this.http.get("/student/allstudent").
        pipe(
            map((data: any) => {
                return data;
            })
        )
    }
}
public getStudentDetails():可观察{
返回此.http.get(“/student/allstudent”)。
烟斗(
地图(数据:任意)=>{
返回数据;
})
)
}
}

通常,该路线的计算结果为
http://localhost:4200/student/allstudent
但代理将采用路径
/student/allstudent
,并将其映射到
proxy.conf.json
中列出的
目标,即
http://localhost:8083

非常感谢您的建议。实际上,我的代理中只有8083,我提到的是8080。但是我试着按照你的想法改变了获取方法。现在我可以在浏览器中看到我的get url。但它并没有被8083取代。你能帮帮我吗。我想你是在跟我开玩笑。非常感谢你的帮助。按照get方法中的说明更改url后。它像冠军一样成功。非常感谢您的快速帮助。如果您能接受并投票决定答案,那就太好了。以上改变效果显著。在这之前,我只想加载express server,从请求头中检索我的组织SSO登录用户,然后从请求头继续。你能用app.js文件指导我吗。我将在下一篇评论中发布我的app js文件。我有app.js,如下所示,但其给出的状态代码404未找到。const express=require('express');const http=require('http');const path=require('path');const request=require('request');常量app=express();var cors=require('cors')app.use(cors())const port=process.env.port | 4200;app.use(express.static(uu dirname+'/dist/myapp');app.get(“/*”,(req,res)=>res.sendFile(path.join(uu dirname));app.post(“/”,函数(req,res){console.log(req.headers);//发布的数据console.log(req.query.module);res.sendStatus(200)});
public getStudentDetails(): Observable<any> {
    return this.http.get("/student/allstudent").
        pipe(
            map((data: any) => {
                return data;
            })
        )
    }
}