SAP-samples / multi-cloud-html5-apps-samples

Examples of HTML5 applications for multiple SAP BTP environments. The examples show how you can use standalone application routers or managed application routers to achieve different goals, and they demonstrate the capabilities of the SAP HTML5 Application Repository service for SAP BTP.
Apache License 2.0
121 stars 103 forks source link

Destination to service module #27

Closed laszloKajan closed 3 years ago

laszloKajan commented 3 years ago

Dear @IObert Marius! [feature request] Could we have an additional / extended example that shows how to define a destination in the mta.yaml to a service module - say CAPM service module - for a managed app router? (assuming the service module is part of the same MTA as the destination content for the managed app router) Thank you in advance. Best regards, Laszlo Kajan

IObert commented 3 years ago

Hi,

I like the idea but I'm afraid I don't know if I'll have time for this in the near future. Having said that, I'll mark the issue with the appropriate labels so that anyone can do a PR for this.

You might want to check out this tutorial if you want to see how this could look in action. In there, you'll learn about a neat way to set everything up.

laszloKajan commented 3 years ago

Thank you for the link to the tutorial, I'll go through it now. Let me see - maybe I can contribute the service module example with Jan Schanzenbaecher's @schanjan help.

T1mey commented 3 years ago

@IObert I think I would need this example as well. It seems that with a managed app router a html5 module isn't able to use a destination provided in the mta.yaml.

Like shown here ... image

How could I consume a rest service of nodeJS application (deployed in the same mta)? Isn't that possible inline (as shown in the image) ? Do I have to configure an own destination ?

Goal is to use the html5 URL and over an entry in xs-app.json the html5 URL with /api/users will be routed to the injected (in mta.yml) destination (nodejs application).

laszloKajan commented 3 years ago

@T1mey I think the approach from this tutorial should work: Add the SAP Launchpad Service / Step 7: Add destinations

Let us know...

T1mey commented 3 years ago

Hello @laszloKajan ,

thanks a lot for your hint! From the first feeling this is nearly that what I wanted... I tried to adapt my mta.yml

image

image

added the route in xs-app.json to and try to invoke my destination

image

If I invoke the expected URL (UI5 invokation URL + /mailapi/test) I get an internal server error

image

Am I doing something wrong ? Is there any way to see the logs of the managed app router ? This should be a standard usecase .... invoking a service (hosted on CF & part of mta) from an SAPUi5 application. Would be great to have an example in this repo for that.

T1mey commented 3 years ago

I got it ... while writing the last post... took the wrong destination name in xs-app.json !

Is there a way that I contribute my work to this repo ?

IObert commented 3 years ago

Sure, I'd appreciate this!

It'd be great if the sample could be as generic as possible, but we can discuss the details once you opened a PR.

T1mey commented 3 years ago

A foolow up question,....

my nodeJS app tries to retrieve the logged in user ...

image

as in mta.yaml Authentication: OAuth2UserTokenExchange is set... this should work. But right now it isn't. Any clue ?

IObert commented 3 years ago

The code looks right, the error must be somewhere else (maybe in the xs-app.json) or so

T1mey commented 3 years ago

The code looks right, the error must be somewhere else (maybe in the xs-app.json) or so

You were right ... authenticationType: xsuaa

;-)

IObert commented 3 years ago

I'll mark this issues as resolved as we just merged PR #28

Please reopen if you think this doesn't cover this issue.

luizcarlospedrosogomes commented 2 years ago

Hello @laszloKajan ,

thanks a lot for your hint! From the first feeling this is nearly that what I wanted... I tried to adapt my mta.yml

image

image

added the route in xs-app.json to and try to invoke my destination

image

If I invoke the expected URL (UI5 invokation URL + /mailapi/test) I get an internal server error

image

Am I doing something wrong ? Is there any way to see the logs of the managed app router ? This should be a standard usecase .... invoking a service (hosted on CF & part of mta) from an SAPUi5 application. Would be great to have an example in this repo for that.

I have a similar problem

luizcarlospedrosogomes commented 2 years ago

image

mta.yaml

ID: targetmngtui
_schema-version: 3.2.0
version: 0.0.1
build-parameters:
  before-all:
    - builder: custom
      commands:
        - npm install

modules:
  - name: targetmngtui-destination-service-content
    type: com.sap.application.content
    requires:
      - name: target-mngt-authentication
        parameters:
          service-key:
            name: target-mngt-authentication-key
      - name: targetmngtui_html_repo_host
        parameters:
          service-key:
            name: targetmngtui_html_repo_host-key
      - name: targetmngtui-destination-service
        parameters:
          content-target: true
    parameters:
      content:
        instance:
          destinations:
            - Name: target-mngt-api
              Authentication: OAuth2UserTokenExchange
              ServiceKeyName: target-mngt-api-key
              ServiceInstanceName: target-mngt-api 
              sap.cloud.service: target-mngt-api              
            - Name: targetmngtui_html_repo_host
              ServiceInstanceName: targetmngtui_html_repo_host
              ServiceKeyName: targetmngtui_html_repo_host-key
              sap.cloud.service: basic.service
            - Authentication: OAuth2UserTokenExchange
              Name: target-mngt-authentication
              ServiceInstanceName: target-mngt-authentication
              ServiceKeyName: target-mngt-authentication-key
              sap.cloud.service: basic.service
          existing_destinations_policy: update
    build-parameters:
      no-source: true
  - name: targetmngtui_ui_deployer
    type: com.sap.application.content
    path: .
    requires:
      - name: targetmngtui_html_repo_host
        parameters:
          content-target: true
    build-parameters:
      build-result: resources
      requires:
        - artifacts:
            - HTML5Module-content.zip
          name: HTML5Module
          target-path: resources/
  - name: HTML5Module
    type: html5
    path: HTML5Module
    build-parameters:
      builder: custom
      commands:
        - npm run build
      supported-platforms: []
  - name: uimodule
    type: html5
    path: uimodule
    build-parameters:
      builder: custom
      commands:
        - npm run build:uimodule --prefix ..
      supported-platforms: []
resources:
  - name: targetmngtui-destination-service
    type: org.cloudfoundry.managed-service
    parameters:
      service: destination
      service-name: targetmngtui-destination-service
      service-plan: lite
      config:
        HTML5Runtime_enabled: true
        version: 1.0.0
  - name: targetmngtui_html_repo_host
    type: org.cloudfoundry.managed-service
    parameters:
      service: html5-apps-repo
      service-plan: app-host
  - name: target-mngt-authentication
    type: org.cloudfoundry.existing-service
    parameters:
      service-name: target-mngt-authentication
  - name: target-mngt-api
    type: org.cloudfoundry.existing-service

xs-app.json

{
  "welcomeFile": "/index.html",
  "authenticationMethod": "route",
  "routes": [
    {
      "source": "^/target-mngt-api/(.*)",
      "target": "$1",
      "destination": "target-mngt-api",
      "scope": ["target-mngt-authentication!t22482.PartnerSales"],
      "authenticationType":"xsuaa"
    } ,
    {
      "source": "^/user-api(.*)",
      "target": "$1",
      "service": "sap-approuter-userapi"
    },
    {
      "source": "^(.*)",
      "target": "$1",
      "authenticationType": "xsuaa",
      "service": "html5-apps-repo-rt"
    }
  ]
}

in localhost, working

nicoschoenteich commented 2 years ago

Hi @luizcarlospedrosogomes,

I can't really see a problem with your code at a first glance, but I'd suggest to check this working example. I know it's a little different than your example because it creates a new instance level destination during deploy time rather than using an existing one, but I think you should give it a shot.

BR, Nico

PS: Please you syntax highlighting for the fenced code block next time 🙏🏻

luizcarlospedrosogomes commented 2 years ago

Before opening the issue I followed exactly the example you gave me. Problem is, how close are the scenarios of the examples to the real ones? Will I always create an xsuaa service or will I use an existing application? Will I always create a static destination or will I create one in BTP and reuse the configuration? Finally, the examples help to get an idea but not to solve real world problems.

Thanks for the answer

I solved the problem by using another example repository and joining the information from this to the other.