Giter Club home page Giter Club logo

micro-lc's Introduction

micro-lc

Mia-Platform

npm version npm downloads License ts

Introduction

micro-lc is an open source micro-frontend orchestrator for building flexible, multi-tenant frontend applications. And much more!

Tip: use the official playground to try micro-lc immediately.

An introduction about micro frontend and how micro-lc works:

micro-lc introduction

Installation

micro-lc is shipped as an ES module CDN bundle and can be imported in any HTML page. Moreover, a dockerized webserver is available on Docker Hub.

Read the docs to learn how you can use micro-lc in your next project!

Handle the repo

Build

This repository is made of 5 subpackages. The dependencies can be sketched as follows:

  `interfaces`
           |
    `composer`
           |
`orchestrator` `iconic`
           |    |
          `layout`

to build the packages there's a script which can be invoked after install as

yarn initialize [OPTIONS]

where OPTIONS are

  1. -c or --cleanup
  2. one of the subpackages: interfaces, iconic, composer, orchestrator, and layout (default)

By using cleanup you require initialize to trash anything in the dist, node_modules, and coverage directories. By choosing one subpackage, initialize will build up to that one.

To build the repository disregarding previous actions run:

yarn initialize --cleanup

Shortcuts

Yarn allows to invoke scripts onto subpackages in a workspaces environment. Such commands might become soon verbose since to build a subpackage the command would be like:

yarn workspace @micro-lc/orchestrator build

hence we enforced some shortcuts:

  1. workspace @micro-lc/interfaces -> i
  2. workspace @micro-lc/iconic -> c
  3. workspace @micro-lc/composer -> m
  4. workspace @micro-lc/orchestrator -> o
  5. workspace @micro-lc/layout -> l

hence the command above would become:

yarn o build

Test

To run tests ensure some CommonJS to ESM conversion on dependencies by running

yarn prepare-test

then simply run

yarn test

or

yarn coverage

Components Playground

layout is a webcomponents repository and provides a storybook environment. Remind to build dependencies as prompted before and then run:

yarn l storybook

A local playground is also available. Run:

yarn playground

to start the playground, and:

yarn playground-stop

to stop it.

Tag

To create a tag, a custom script is provided. Given the library/package you'd like to tag:

  • orchestrator
  • composer
  • layout
  • iconic
  • interfaces

just run

yarn bump <PACKAGE> [major|minor|patch|<VERSION>]

which will:

  1. update the changelog moving the unreleased entries to the tagged version
  2. create the appropriate tags for npm libraries and docker containers

Notice that orchestrator release, on tag, both the npm library and a docker container, hence carries 2 tags simultaneously.

Contributing

We are thankful for any contributions from the community, read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to micro-lc.

Licence

micro-lc is Apache 2.0 licensed.

micro-lc's People

Contributors

amountainram avatar clabene avatar davidebianchi avatar dependabot[bot] avatar epessina avatar eros-piccioni avatar evange95 avatar fabionappi avatar fredmaggiowski avatar giogia avatar giulioroggero avatar hiimjako avatar ilteoood avatar liliumcandidum avatar lucascanna avatar ugho16 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

micro-lc's Issues

[Bug] Wrong response content-type getting the micro-lc-base.js file

Hi guys,
we noticed that the route /configuration/micro-lc-base.js returns correctly the javascript file, but with the wrong content-type:

$ curl localhost:3000/v1/microlc/configuration/micro-lc-base.js -v
*   Trying 127.0.0.1:3000...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET /v1/microlc/configuration/micro-lc-base.js HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.84.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< content-type: text/plain; charset=utf-8
< content-length: 135
< Date: Tue, 22 Nov 2022 10:58:19 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
<
...
...
...

As you can see, the content-type is set to text/plain instead of application/javascript.
For this reason, micro-lc doesn't work with some api-gateway.

Can you fix it?

Add options to inject external sytlesheet into plugins

Problem

Currently, micro-lc allows to orchestrate micro-frontends coming from different sources, but since these micro-frontens can vary a lot in UI design, there is a high risk to obtain a overall result which lacks in visual consistency (expecially when the injected plugins offer low to zero support for UI customization).

Proposal

A solution for the issue could be to offer the possibility of injecting a custom stylesheet for the plugins, either at general level (e.g. in the theming section of the config) or inside the configuration of the specific plugin. The former solution could be better for consistency, since the same style is defined only once, but the latter could allow a higher level of precision and avoid to mix styles that are intended to be effective only on a specific micro-fe.

The stylesheet could be injected either by typing directly the CSS code inside the configuration (see example below) or by contacting a specific url passed in the configuration. The first solution is maybe simpler, but could lead to messy configuration if the number of CSS rules to be applied is high.

// example of a configuration
{
  "theming": {
    "header": {
      "pageTitle": "Test",
      "favicon": "https://www.test.it/favicon"
    },
    "logo": {
        ....
    },
    "customCSS": {
        "button.my-button": {
             "background-color": "red",
             "color": "FFFFFF",
             ...
        }
    }

Eventually, micro-lc could then apply specific prefixes to the provided selectors to increment the specificity of the rules:

// example of the result CSS rule
#micro-lc-container button.my-button {
     background-color: red;
     color: "FFFFFF";
     ...
}

Hide menu option

It would be great to have an option in the configuration to hide the navigation menù in order to have a much clearer solution using the routing to load plugins and don't force the user interface to implement the menù

Opening drawer causes page to be moved up

I have a page configured by means of the element composer. The configuration is available as attachment in this issue (as *.zip because github doesn't allow the upload of json).
config.json.zip

The page is rendered correctly but there's a problem when the user clicks on "Aggiungi filtro" (add filter), or whenever the user opens the lateral drawer. In that case, for some reason the entire page is moved upwards (see the attached gif: the header is no longer visible after the lateral drawer has been opened). The page stays like that even when the drawer is closed and even if the user navigates to a different section of the website. The only way to get rid of the shift towards the top of the screen is to refresh the page.

Registrazione.schermo.2022-08-23.alle.11.14.46.mov

Browser: Chrome 103.0.5060.134(arm64)
OS: Mac OS Monterey 12.3.1
Micro-lc version: 0.6.2 (we tried 0.8.0 as well)
Micro-lc element composer version: 0.4.1 (we tried 0.6.0 as well)

Unexpected behaviour when routing

I'm using micro-lc with docker-compose in a local environment and I'm also rewriting the index.html file.
I have a simple configuration with only a route /home, which is also the defaultUrl. The route integrationMode is of type compose.

When I open it, it works correctly and it loads the configured page. I would expect the same behaviour if I went to /home/:something but it shows a 404 page.
If I add <base href="/" target="_blank"/> to my index.html and I go to /home/:something, it works as expected and shows the configured page.

I'm using micro-lc version 2.0.9

This is my index.html:

<!DOCTYPE html>
<html lang="en">
<head>
  <base href="/" target="_blank"/>
  <title>micro-lc</title>
  <link rel="icon" href="https://avatars.githubusercontent.com/u/92730708?s=200&v=4" />

  <script type="module" src="https://cdn.jsdelivr.net/npm/@micro-lc/orchestrator@latest/dist/micro-lc.production.js"></script>

  <style>
    html, body {
      position: relative;
      width: 100%;
      height: 100%;
      margin: 0;
    }
  </style>

</head>
<body>
  <micro-lc config-src="./config.json"></micro-lc>
</body>
</html>

micro-lc loading with an heavy bundle

Micro-lc should be able to fire onload event only when first rendered application is ready.

I have a heavy bundle and micro-lc doesn't wait for it, so the loading page stops before the bundle is loaded and doesn't show anything but the notification center for a while.

Separate CDN publish job

Feature Description

Pipeline steps to publish on NPM and Mia CDN should be separated. Moreover, the batch size for Mia CDN should be lowered.

Router matches urls not in configuration

When creating a configuration that defines some routes, it happens that micro-lc router matches also routes that are not explicitly written, but begin with the same string as an existing route.

Example:

config.json:

{
    "version": 2,
    "applications": {
        "customers": {
            "config": "/customers.json",
            "integrationMode": "compose",
            "route": "/customers"
        }
    }
}

The only provided route is /customers, but the router matches also /customersfoo as /customers

Expected behavior

  • Router shouldn't match /customersfoo as /customers

Also take into account the case of query params, path params and anchors.

UI unbundle

Hi guys,
with the following issue I would like to introduce a proposal to unbundle the micro-fe orchestration logic from the provided UI. The purpose of the proposal is to the decouple them and offer to our users the ability to build a custom UI around the orchestrator.

How we can divide it?

In the following picture I selected with an orange rectangle the part that should be in the UI package, while I selected with a green rectangle the part that should be in the orchestrator package.
image

How to re-organize it?

In order to encourage the creation of other UIs for micro-lc, I suggest to move the current UI part into a new repository. It can be seen as a net detachment, but I think that can be useful as base project to start your own new UI around micro-lc, to facilitate potential new users.

Technical approach

To follow the micro-lc's framework-agnostic principle, I suggest to keep a framework-agnostic approach even in this solution.
The UI around it can be done with every framework or even vanilla (for example, we will keep our UI made with React): to make it possible, micro-lc must be available as web-component.
The web-component, that is framework-agnostic by design, will act as always: it will call /api/v1/microlc/authentication and /api/v1/microlc/configuration and will manage the micro-frontend loading according to the defined pluginRoute.

Distribution methods

To facilitate the integration in other UIs, I suggest to make the micro-lc web-component available as npm package.
The current Docker Image will still be available, for who wants to use it as an application shell.
Also, a new Docker Image will be available for the default UI that we provide, to give the same deployment approach that we already provide.

Breaking changes

All this kind of work involve in a lot of breaking changes.
I tried to make a rough estimate, and here follows the results:

  • The micro-lc core configuration, exposed through /api/v1/microlc/configuration, will not contain anything about theming, analytics and so on. It will contain only the plugins' configuration.
  • The current plugin configuration in the core will loose all the UI-related information, as label, icon and order because it will not manage its display anymore.
  • The UI configuration will be exposed with the /api/v1/microlc/configuration/{configurationName} API, and will include the informations about theming, analytics... previously excluded.
  • In order to correctly associate a plugin with its labels, icons and behavior, will be used the plugin id.

An example of a new core configuration can be:

{
  "plugins": [
    {
      "id": "plugin-1",
      "aclExpression": "groups.admin || groups.superadmin",
      "integrationMode": "qiankun",
      "pluginRoute": "/myAwesomePlugin",
      "pluginUrl": "https://plugin-url.com",
      "props": {}
    },
    {
      "id": "plugin-2",
      "integrationMode": "href",
      "externalLink": {
        "url": "https://external-site.com",
        "sameWindow": false
      }
    }
  ]
}

While an example of configuration for the UI can be:

{
  "theming": {
    "header": {
      "pageTitle": "Mia-Platform",
      "favicon": "https://favicon-url.com"
    },
    "logo": {
      "url_light_image": "https://logo-url.com/light",
      "url_dark_image": "https://logo-url.com/dark",
      "alt": "My awesome logo"
    },
    "variables": {
      "primaryColor": "red"
    },
    "menuLocation": "topBar"
  },
  "analytics": {
    "privacyLink": "https://policies.google.com/",
    "disclaimer": "We use analytics cookies for...",
    "gtmId": "GTM-XXXXXX"
  },
  "plugins": {
      "plugin-1": {
          "label": "Plugin number 1",
          "icon": "fas fa-rocket",
          "order": 0,
      },
      "plugin-2": {
          "label": "Plugin number 2",
          "icon": "fas fa-TAG",
          "order": 1,
      }
  }
}

BE CAREFUL: the above UI settings will be used by the UI that we already provide. If a user wants to create his UI from scratch, he can create his own configuration

Communication interfaces between UI and micro-lc

In order to communicate to the UI the plugins that has been loaded with micro-lc, we can use two approach:

  1. Make them available in an freezed object stored inside the window;
  2. Include them in the detail part of a Custom Event.

I prefer the second approach, as it results much cleaner IMO.

Conclusions

This refactoring will make micro-lc more general purpose, and will allow our teams to customize the UI around each customer needs.

Let me know what do you think about it!

Support SEO

We must provide support for SEO.
We've already made an image of prerender that can be used as sidecar: now we should configure the NGINX instance of micro-lc in order to redirect the crawler traffic to that sidecar.

It should be something similar to this

qiankun-head base url

Description
The href attribute of the <base> tag inside <qiankun-head> should contain only the route configured in the config file but it contains the complete url (excluded the base).

I'm serving configurations using version 2.0.8.

Reproduction
Configure a micro-frontend on a route (ex. /my-microfronted/) and open the page adding one or more subdirectory to the url (ex. localhost/my-microfrontend/user/value). Open the inspector and inside the <qiankun-head> tag there is the <base> tag with an href attribute. The href value will be something like /my-microfrontend/user/value instead of just /my-microfronted/

Configurable menu on click on user avatar in header

At the moment, in the page header, upon clicking on the user avatar, a menu with only one CTA is shown, and the action is "disconnect".
Schermata 2022-03-15 alle 09 55 03

It'd be useful to be able to configure other CTAs, like a simple link to the profile section.

2 simplest projects Vue3 Typescript Vite integration

I have try to find integration of micro-lc with Vue projects but I don't found any.

So I have created two hello world VUE3 TYPESCRIPT VITE projects and make the base configuration with micro-lc.
https://github.com/clabnet/microlc-vue

The actual result is the start of micro-lc page with a 400 error, and 500 errors when activating MFE1 or MFE2.

Do you like please support me to configure correctly for run the two simple projects as "parcel" mode ?

Thank you very mutch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.