cancel
Showing results for 
Search instead for 
Did you mean: 

MTA on Cloud Foundry with Html5 App Repo and Approuter

former_member603667
Participant

Hi SAP!

I was experimenting to build a full-stack app on cloud foundry with a nodejs and a html5 module. I first created a MTA without html5 app repo and it worked fine (especially routing, what this question will be about). Then I created a MTA with a html5 app repo (I checked the checkbox, when creating the html5 module) to take advantage of it and now routing to my nodejs-backend-module does not work anymore. There's always an internal server error.

I've read on the sap help site, that when using html5 app repo AND approuter, the property "destination" is not supported (which I had in the mta without html5 app repo to forward request to the module). So how can I forward requests to my backend module then?

The following shows the approuter with the route to the html5 app repo. When I add a second route with property destination, it does not work anymore.

{
	"welcomeFile": "/index.html",
	"authenticationMethod": "route",
	"logout": {
		"logoutEndpoint": "/do/logout"
	},
	"routes": [{
		"source": "^/(.*)$",
		"target": "$1",
		"service": "html5-apps-repo-rt",
		"authenticationType": "xsuaa"
	
        },{ // PART THAT DOES NOT WORK
		"source": "^/api/([a-z]+)",
		"target": "/$1",
		"destination": "nodejs_repo_api"
	}
]
}

This is mta.yaml file:

ID: mta_test_modules_repo
_schema-version: '2.1'
parameters:
  deploy_mode: html5-repo
version: 0.0.1
modules:
  - name: mta_test_modules_repo_appRouter
    type: approuter.nodejs
    path: mta_test_modules_repo_appRouter
    parameters:
      disk-quota: 256M
      memory: 256M
    requires:
      - name: mta_test_modules_repo_html5_repo_runtime
      - name: uaa_mta_test_modules_repo

  - name: mta_test_modules_repo_ui_deployer
    type: com.sap.html5.application-content
    path: mta_test_modules_repo_ui_deployer
    requires:
      - name: mta_test_modules_repo_html5_repo_host
    build-parameters:
      requires:
        - name: destination_service_frontend
          artifacts:
            - './*'
          target-path: resources/destination_service_frontend

  - name: nodejs_repo
    type: nodejs
    path: nodejs_repo
    provides:
      - name: nodejs_repo_api
        properties:
          url: '${default-url}'
     
  - name: destination_service_frontend
    type: html5
    path: destination_service_frontend
    parameters:
      disk-quota: 500M
      memory: 500M
    build-parameters:
      builder: grunt
    requires:
      - name: nodejs_repo_api
        group: destinations
        properties:
          name: nodejs_repo_api
          url: '~{url}'
          forwardAuthToken: true
      - name: uaa_mta_test_modules_repo
 
resources:
  - name: mta_test_modules_repo_html5_repo_runtime
    parameters:
      service-plan: app-runtime
      service: html5-apps-repo
    type: org.cloudfoundry.managed-service

  - name: mta_test_modules_repo_html5_repo_host
    parameters:
      service-plan: app-host
      service: html5-apps-repo
    type: org.cloudfoundry.managed-service

  - name: uaa_mta_test_modules_repo
    parameters:
      path: ./xs-security.json
      service-plan: application
      service: xsuaa
    type: org.cloudfoundry.managed-service

  - name: dest_mta_test_modules_repo
    parameters:
      service-plan: lite
      service: destination
    type: org.cloudfoundry.managed-service

Accepted Solutions (0)

Answers (9)

Answers (9)

WouterLemaire
Active Contributor

I also had the "internal server error" when testing my generated UI5 app. I found out that it was because of wrong configuration of the uaa resource in the mta.yaml file. I changed it to the following:

resources:
  - name: myMTAApp-uaa
    type: org.cloudfoundry.managed-service
    parameters:
      path: ./xs-security.json
      service-plan: application
      service: xsuaa

If that doesn't help, you should check the logs in CloudFoundry. The logs will provide more details about the "internal server error".

Kr, Wouter

iashishsingh
Participant

Hi Paige,

Have you tried putting the api route first? From what I notice, in every case the first route will be matched and triggered. This is how your xs-app.json should look like with 'routes' modified:

{
	"welcomeFile": "/index.html",
	"authenticationMethod": "route",
	"logout": {
		"logoutEndpoint": "/do/logout"
	},
	"routes": [{ // PART THAT DOES NOT WORK
		"source": "^/api/([a-z]+)",
		"target": "/$1",
		"destination": "nodejs_repo_api"
	}, {
		"source": "^/(.*)$",
		"target": "$1",
		"service": "html5-apps-repo-rt",
		"authenticationType": "xsuaa"
	
        }
]
}

Let us know how this goes.

former_member603667
Participant
0 Kudos

Hi ashish.singh23,

thank you for your answer.

Yes, I already tried this, but the module can not be found anyway. Once, I also added a /ui5/ to the repo-route for determination, but then the index.html can not be found in repo.

The approuter module is the one that should access the backend (from nodejs_repo module), therefore you need to require it there.

In other words, move the:

requires:-name: nodejs_repo_api
        group: destinations
        properties:name: nodejs_repo_api
          url:'~{url}'
          forwardAuthToken: true

From the destination_service_frontend module to the mta_test_modules_repo_appRouter module, build and deploy. With this approuter should be able to find destination nodejs_repo_api

former_member603667
Participant
0 Kudos

Hi sergio.rozenszajn, thank you for your answer.

Unfortunately this does not work either, the result is "Not found". I already tried it a while ago and now again.

Have you already tried it by yourself, so do you have already experience with this case?

I also changed the sequence of the two routes, so that /api/ is first, but this have not changed anything. And I added a /ui5/ to the repo-route, but then it can't find the index.html in repo.

I think it must be simple, because without the repo it is, too, but I just can't find an answer to this question.

seankogn
Explorer
0 Kudos

Similar issue, this solution worked! Thanks

dhiraj_jaiswal
Advisor
Advisor
0 Kudos

Hi,

Thank you for clarification above. May I know what will be the solution in this case if we are using a managed app router?

Anuj07
Employee
Employee
0 Kudos

Hi paigeola,

I am also facing this issue. In case if you have resolved it then please let me know.

Thanks!

Best Regards,

Anuj

ravindrapawar
Participant
0 Kudos

Hi,

I resolved internal server error and manged routing to my nodejs-backend-module with above comments/answers. But static contents in folders like i18/model/css of html5 module are not loading with html5 application repository. Without html5 application repository it works as expected.

Tried by adding "localDir" in the 1st route of xs-app.json but it is not helping.

Any pointers please.

Thanks,

Ravindra

0 Kudos

Hi,

I had the same issue and I just missed the requirement of the destination service for the app router. So adding the following line in mta.yaml fixed it for me:

ID: mta_test-cf
_schema-version: '2.1'
parameters:
  deploy_mode: html5-repo
version: 0.0.1
modules:
  - name: mta_test-cf_appRouter
    # ....
    requires:
      - name: mta_test-cf_html5_repo_runtime
      - name: uaa_mta_test-cf
      - name: dest_mta_test-cf # <-------------------- this line fixed it
    # ...
resources:
  # ....
  - name: dest_mta_test-cf # <------------------------ name needs to match this 
    parameters:
      service-plan: lite
      service: destination
    type: org.cloudfoundry.managed-service

Cheers,

Patrick

0 Kudos

Hi Ola,

Yes I also faced this issue and resolved it the same way by changing the target attribute.

You can also debug the approuter and check what is the URL getting generated after the destination and target is resolved.

cf set-env App_Router_App_Name XS_APP_LOG_LEVEL DEBUG

cf restage App_Router_App_Name

Replace the App_Router_App_Name with the appRouter application.

Run the application again after executing the above 2 commands and check the logs of appRouter application.

Regards,

Puneet

0 Kudos

Hi Ola,

To resolve this issue do the following:

a) Move the destinations to AppRouter module as defined by Sergio Rozenszajn.

b) Change the target field in the routes:

Instead of "target": "/$1"

change it to "target": "api/$1"

Regards,

Puneet

former_member603667
Participant
0 Kudos

Hi jain.puneet20,

thank your for your answer. Unfortunately this does not work for me either. It's still Not Found. Are you sure, that this must be the reason to resolve the issue? Have you had this case already?

Best regards!