Is there a way to have the client side script also auto loaded from the proxy/cluster services in the Ara Framework?

372 views Asked by At

First of all a great framework for SSR based MFEs . I was trying out the Ara / Svelte (Micro App1) / Vue (Micro App 2) / Nuxt JS (Appshell) as described in https://ara-framework.github.io/website/blog/2019/08/27/nuxt-js as well as setup the cluster and proxy as described in the docs https://ara-framework.github.io/website/docs/nova-cluster

In the App shell in the Nuxt App I need to include the client side scripts like this

  head: {
    script: [
      { src: 'http://localhost:3000/public/client.js' },
      { src: 'http://localhost:3001/public/client.js' }
    ]
  }

Is there a better way to discover and load this scripts , similar to the server side part is handled by the proxy and the cluster servers ? The problem with the current approach is I need to know where the nova server client scripts are deployed before hand.

1

There are 1 answers

0
Felipe Guizar Diaz On

As you describe in the comments, using the NovaMount event is the best approach so far. Unfortunately, there's nothing out of the box to do it without explicitly define the bundle URLs yet.

However, we plan to add a new feature to Nova Proxy to make that easier.

In the getComponent helper, we can use the returnMeta property from the second parameter to return the client script URL in the Hypernova response.

hypernova({
  getComponent (name, { returnMeta }) {
    returnMeta.src = 'http://localhost:3000/public/client.js'
  }
})

We get something like this in the Hypernova response.

{
    "success": true,
    "error": null,
    "results": {
        "example": {
            "name": "Example",
            "HTML": "...",
            "meta": {
                "src": "http://localhost:3000/public/client.js"
            },
            ...
        }
    }
}

We plan to inject that client URL in Nova Proxy when including the Nova views as well.

I created this Github issue where you can follow-up on the feature progress. https://github.com/ara-framework/nova-proxy/issues/10