3

My proxy config not working as it is not redirecting as per rewrite config Below is my proxy.config.json

{
    "/sap": {
        "target" : "http://server.domain.com:8002",
        "secure" : false,
        "pathRewrite": {
            "^/sap": ""
        },
        "changeOrigin": true,
        "logLevel": "debug"
    }

}

Below is my http call this.http.get('/sap/opu/odata/sap/ABC_FD_SRV/ID_GEN_Set?sap-client=010', {headers}).pipe(map((response: any) => response));

Headers used for the http request

var headers = new Headers();
        headers.append('Content-Type', 'application/json');
        headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT');
        headers.append('Accept', 'application/json ');
        headers.append('X-Requested-With','XMLHttpRequest');

Whenever i use ng serve --proxy-config proxy.config.json to start and check in the networks tag instead of http://server.domain.com:8002 it redirects to http://localhost:4200

i have tried with /sap/* but no use. Can anyone help me to solve this problem i am working out to call odata link to consume the data from the server so i have used changeOrigin: true for cross origin browser problem.

1 Answer 1

4

If you meant that you only see http://localhost:4200 in your Networks tab, it's OK. From the browser, it goes out as 4200. Proxying happens in your host server. What is the response to your call?

Sign up to request clarification or add additional context in comments.

3 Comments

empty in the response
If you don't get any errors, I would assume that your request found its destination. You already set logLevel to debug, which is very smart. In your console, when you started your server with ng serve, do you see any logs regarding path rewrite?
Ok. So, in your Networks tab, you see localhost:4200 because that is what your Angular application sends. The call gets to your host server, which looks up rewrite rules from your proxy.config.json. It finds a matching rule, makes the rewrite and forwards the request. You should see a 404 response code if your rewrite didn't work. But you said that you don't get any errors, only an empty response (btw, is the response code 200?). So clearly it had to reach your server, I assume that your response is, in fact, empty because the server returns nothing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.