0
votes

I'm getting this error

GET http://localhost:8888/ui5/projects/po_cond/app/proxy/http/xx.yyy.net:8000/sap/opu/odata/SAP/ZXXX_SRV/$metadata 404 (Not Found)

Below is my code for url assignment

             var sServiceUrl = getServiceUrl("http://xx.yyy.net:8000/sap/opu/odata/SAP/ZXXX_SRV");  

     function getServiceUrl(sServiceUrl) {  
        var sOrigin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" +                                          window.location.port : "");  
        if (!jQuery.sap.startsWith(sServiceUrl, sOrigin)) {  

             return "proxy/" + sServiceUrl.replace("://", "/");  
        } else {  
              return sServiceUrl.substring(sOrigin.length)  
        }  
    }  

Is there anythinh that I'm missing

Thank you

1
Does the server that's listening on 8888 have this proxy service it looks like you're trying to use? From the URL pattern and the context, perhaps you're trying to use something that would normally be found in Eclipse-based tomcat examples from SAP?qmacro
Do you get the metadata document using this URL? xx.yyy.net:8000/sap/opu/odata/SAP/ZXXX_SRV/$metadataMikael G
@qmacro how do I make the proxy service available with node.js? I have 'moved back' to eclipse and have used simple proxy sevlet an my app is working. I want to make it work from node jswillard Chingarande
@MikaelG yes i am getting the metadata documentwillard Chingarande
node.js itself is "just" a JavaScript runtime. You'll need to write your own proxy service, either from scratch or based on a module. This is likely not something that can be covered in detail on a Q&A entry here in SO. For your intentions (that I'm assuming) it may just be easier to use Chrome's --disable-web-security parameter on startup.qmacro

1 Answers

1
votes

User qmacro basically answered the question in his two comments. However, I feel that both the original poster (OP) and the general audience need some background to really understand the problem and the suggested solution. So I first want to rephrase the problem and then offer a solution.

Rephrasing the Problem

The root cause of the problem is, that the JavaScript Code showed by the OP in his question, is pulled from a local web server, in this case http://localhost:8888, and then this JavaScript code wants to call an OData Service at http://xx.yyy.net:8000 in the background (using the XMLHttpRequest-Object). This violates the Same Origin Policy (SOP) enforced by almost all browsers which states, that such background calls are only allowed to the same combination of protocol (http), server (localhost), and port (8888).

One common solution for this problem is to have a proxy inside the local server, which forwards all requests of a specific form (in our case http://localhost:8888/proxy/\*) to a remote address (in our case http://xx.yy.net:8009/\*).

The local server receives the call, and the proxy inside the local server (which is not subject to the SOP) forwards it to the OData service. For the Browser everything looks OK.

Why it runs in Eclipse

SAP has provided such a proxy in form of a Java Servlet. This proxy can be run in any Java based Web Server used by Eclipse (the built-in Jetty, or any other Web Server like Tomcat). The OP obviously was able to get this Eclipse-provided web server running and configure the SAP-provided proxy correctly.

Why it does not run in node.js

Simply because the node.js Application the OP apparently wants to implement is not able to run the Java proxy. What is needed instead is some JavaScript Proxy within the node.js server. There are loads of such proxies available. The first one I found while googling was https://www.npmjs.com/package/json-proxy, but there are many more available.