2
votes

I'm trying to run my ui5 pages on Node.js server. What I've done till now is created a UI5 project with a simple index.html file calling my other ui5 views showing a text message. When I run it without node js it runs fine and shows me the message.

What I'm trying to achieve now is run this on top of my node server. So I've configured a server.js file for my node and it starts up fine. In there I'm calling up my above index.html file. it calls it fine but it gives an error inside it saying sap is undefined meaning it is not able to find my ui5 resources like sap-ui-core.js and thus the error. I'm not sure why it is not able to find it.

I've created the ui5 project using eclipse which provides me the ui5 resources under the below directory but even if I try to put the resources directory under the web content directory it is not able to find it.

enter image description here

After manually putting resources directory:

enter image description here

Below is how my index.html looks like:

enter image description here

Has it got something to do with the resource root that I define or please if you can suggest how can I get it working.

Awaiting your responses eagerly.

Thanks, AW

Adding to cschuff response:

Hello, thanks for taking time to help me out. Yes my apps namespace is different and definitely not something with sap.ui. Though I've got a way around of getting it to work but still would like to get this to work as well as it is much cleaner. The way I've got it working now is by creating a seperate node project altogether and then gradually adding my UI5 pieces to it and by gods grace it is running fine now. But I'm not sure why the same concept if I apply on a UI5 project created in eclipse, it gives me sap is undefined error.

enter image description here

2
Hello All, I see when I try to run the index.html outside node js it is trying to look for the other js files within the sap ui directory for which it fails to load them giving access denied error but not sure why. So why it is not able to run on the node js server??user3905218
What does the network tab say from where it tries to load sap-ui-core.js?cschuff

2 Answers

0
votes

My only suggestion that you misconfigured node.js server. Try start from scratch:

mkdir app
cd app
npm install -g express-generator
express -f
npm install
node .\bin\www

Than put all of your files of your project and resource in public directory. And try to open http://localhost:3000/index.html

0
votes

The /resources are delivered by the com.sap.ui5.resource.ResourceServlet (see your web.xml; web.xml and Servlets are used in the Java World e.g. by Java Application Servers or Servlet Containers like Tomcat)

The ResourceServlet listens on the url-pattern /resources/* meaning every time a request is send to an url matching this pattern the ResourceServlet (a Java class) will step in, look up the right .jar file and return the required JavaScript file from it. This won't work with a plain web server like Apache.

I don't know much about express but I guess it is not able to run Java Servlets and thus is not able to deliver your SAPUI5 resources the same way Tomcat does.

To work around this you still have some options:

  1. Use Express to serve your application sources and load UI5 from Tomcat while developing. This might lead to cross-origin problems (since localhost:8080 and localhost:3000 are considered different origins)

    <script src="http://locahost:8080/resources/sap-ui-core.js" ...

  2. Unpack all the UI5 .jars you need and place them in YourApplication/resources/.

enter image description here

BR Chris