# ui-middleware

> Provides the collected manifest.json of services in a cluster as well as a list of dependencies
> for each source file. This information can be used to dynamically compile all ui components at
> runtime in the browser. Besides serving the information about all resources, this service can
> also function to provide snapshots of all the resources available at a specific point in time.

## Architecture

The ui-middleware is, as the name already suggests, a middleware component to support the App Suite UI.
As an installation of App Suite UI can consist of multiple projects, like the [Core App Suite UI](https://gitlab.open-xchange.com/frontend/ui), [Documents UI]([https://gitlab.open-xchange.com/documents/office-web), [OX Guard UI](https://gitlab.open-xchange.com/appsuite/guard-ui), and other custom plugins, those components need to be combined at some point to be served to the browser.
This is handled by the ui-middleware component, by putting it between the Ingress Controller and the containers serving the individual components that make up the App Suite UI.

If you prefer a picture, this is, how such an installation can look like.

![UI Middleware architecture](./docs/ui-mw-architecture.png)

## Endpoint

- `/manifests`
- `/dependencies`

## Deployments

**local**

- adjust `.env`
- run `yarn dev`

**docker**

```
docker build -t ui-middleware .
docker run -t -i -p 8080:8080 ui-middleware
```

**kubernetes**

```
cd helm
helm upgrade -i -f ui-middleware/values.yaml -f values/develop.yaml ui-middleware ./ui-middleware
```

It is possible to horizontally scale the UI Middleware, as more clients are fetching resources from this service. Each instance maintains a cache of all files locally (in memory), allowing to scale easily.

## Configuration

**local, docker**

| Parameter             | Description                     | Default  |
|-----------------------|---------------------------------|----------|
| `PORT`                | Exposed port                    | `"8080"` |
| `CACHE_TTL`           | Vite manifest caching time      | `30000`  |
| `LOG_LEVEL`           | Pino log level                  | `"info"` |
| `REDIS_HOST`          | Redis host (required)           |          |
| `REDIS_PORT`          | Redis port (optional)           | `6379`   |
| `REDIS_DB`            | Redis DB, e.g. `"1"` (optional) | null     |
| `REDIS_PASSWORD`      | Redis password (optional)       | null     |
| `COMPRESS_FILE_SIZE`  | Larger files will be gzipped    | `600`    |
| `COMPRESS_FILE_TYPES` | Set of compression mime types   |see values|


**kubernetes**

| Parameter             | Description                     | Default  |
|-----------------------|---------------------------------|----------|
| `port`                | Exposed port                    | `"8080"` |
| `cacheTTL`            | Vite manifest caching time      | `30000`  |
| `logLevel`            | Pino log level                  | `"info"` |
| `redis.enabled`       | Global switch Redis integration |  false   |
| `redis.host`          | Redis host                      |          |
| `redis.port`          | Redis port (optional)           | `6379`   |
| `redis.db`            | Redis DB, e.g. `"1"` (optional) | null     |
| `redis.password`      | Redis password (optional)       | null     |
| `compressFileSize`    | Larger files will be gzipped    | `600`    |
| `compressFileTypes`   | Set of compression mime types   |see values|

**config map**

```yaml
# List of urls where to find ui containers
baseUrls:
  - http://service.namespace.svc.cluster.local/
# optional, when this number is changed, the changes on clients will be invalidated and will reload the ui-sources
salt: '1234'
```

## Ingress

When using Ingress to make the service available to the public, the service is intended to be
configured as a "fallback" or "default" service to answer all requests that are not specified
to be served by one of the other services (e.g like everything under /api). This should simplify
the Ingress configuration. One example can be found
[in the ui-middleware repository](https://gitlab.open-xchange.com/frontend/Infrastructure/ui-middleware/-/blob/main/.gitlab-ci/kubernetes-resources.yaml).