Skip to content

Example app UI ​

This example adds a dashboard page to an app. The UI is a static Nuxt app built with @n5i/ui and served by a container of the app.

The UI ​

text
my-app-ui/
├── nuxt.config.ts
├── package.json        # depends on nuxt and @n5i/ui
└── app/
    ├── app.config.ts
    ├── app.vue
    └── pages/
        └── index.vue
ts
// nuxt.config.ts
export default defineNuxtConfig({
  extends: ["@n5i/ui"],
  ssr: false,
});
ts
// app/app.config.ts
export default defineAppConfig({
  n5iUi: { host: { app: { name: "My app", version: "1.0.0" } } },
});
vue
<!-- app/app.vue -->
<template>
  <UApp>
    <NuxtPage />
  </UApp>
</template>
vue
<!-- app/pages/index.vue -->
<template>
  <div class="p-6 space-y-6">
    <NPageHeader title="My app" description="Status of the service">
      <template #actions>
        <UButton label="Refresh" icon="i-heroicons-arrow-path" @click="load" />
      </template>
    </NPageHeader>

    <UCard>
      <div class="flex items-center justify-between">
        <span class="text-ink-muted">Service</span>
        <NStatusBadge :status="status === 'ok' ? 'success' : 'danger'" />
      </div>
    </UCard>
  </div>
</template>

<script setup lang="ts">
const host = useHost();
const status = ref<string>();

async function load() {
  // A JWT for this app, from the dashboard; verify it in your API
  const jwt = await host.getJwt();
  const result = await $fetch<{ status: string }>("/api/status", {
    headers: jwt ? { Authorization: `Bearer ${jwt}` } : {},
  });
  status.value = result.status;
  host.toast({ title: "Status updated", color: "success" });
}

onMounted(load);
</script>

Install the dependencies and build it as a static site:

sh
pnpm install
pnpm nuxi generate
sh
npm install
npx nuxi generate
sh
yarn install
yarn nuxi generate
sh
bun install
bunx nuxi generate

Serve the output (.output/public) with any web server, as part of your app's container image. During development, run pnpm nuxi dev.

The app ​

The UI must be served on the app's domain. Here, the main container serves both the UI and its /api:

yaml
# app.yml
version: 1

containers:
  main:
    image: registry.example.com/my-app:1.0.0
    ingress_port: 8080

Add a menu entry in metadata.yml:

yaml
# metadata.yml
version: 2

metadata:
  path: /
  ui_module:
    menu_entries:
      - name: My app
        icon: i-heroicons-signal
        path: /

After the app is installed and has a domain, it appears in the dashboard's sidebar. Selecting it opens /plugin/my-app/ in the dashboard, which shows https://<app domain>/ in an iframe with the dashboard's theme.

Without Nuxt ​

Any web page can be an app UI. With plain JavaScript and @n5i/app-bridge:

ts
import { applyTheme, createAppBridge } from "@n5i/app-bridge";

const bridge = createAppBridge({ app: { name: "My app", version: "1.0.0" } });
bridge.on("theme", (theme) => applyTheme(theme));

const state = await bridge.connect();
if (state.theme) applyTheme(state.theme);

const jwt = await bridge.getJwt();

Style the page with the theme tokens, for example color: var(--nv-ink) and background: var(--nv-surface), and leave the page background transparent.

Free and open-source software under the GNU AGPL 3.0 or later.