Skip to content

Tutorial — Part 5: Interactive Islands, Tests & Deploy

In Part 5, you will learn how to add client-side interactivity without a Node.js bundler (using event directives and Islands compiled from TypeLua to ES Modules), write automated tests with ob test, and ship the entire Mini Blog as a single binary.


1. Progressive Interactivity (@click, @submit.prevent)

For lightweight interactions (toggling a modal, confirming a delete, submitting via fetch), .html templates support Vue-style event attributes that compile to standard data-ob-on-* / data-ob-mod-* attributes:

<button type="button" @click="toggleBookmark" data-post-id="{{ post.id }}">
  Bookmark
</button>

A tiny vanilla script in public/app.js (loaded via {{ asset('app.js') }}) can handle these clicks with zero framework overhead.


2. Interactive Islands (html.island + --target js)

When a widget needs rich client-side state (like an interactive Like Counter or live markdown preview on /posts/[id]), Orbita supports Islands Architecture:

  1. The server renders the full HTML page plus an island container with serialized JSON props via html.island(name, props, fallback):
-- Inside a route loader (e.g. src/apps/posts/routes/posts/[id].tyl)
local html = require("ob:html")

local like_island = html.render(html.island("LikeButton", {
    post_id = post.id,
    initial = 12,
}, "Loading..."))

Insert it in [id].html with triple braces:

{{{ like_island }}}
  1. Write the interactive island component in TypeLua/Luax (src/islands/like_button.luax) and compile it to a zero-dependency ES Module with ob build --target js:
ob build src/islands/like_button.luax --target js -o public/islands/like_button.js

Orbita's JS compiler emits a clean ES Module with a minimal built-in runtime (useState, mount, hydrateIslands) — no node_modules, no Webpack, no Vite required.


3. Automated Testing (ob test)

Create src/apps/posts/posts_test.tyl to test your router, templates, and cache directly in-process (no port binding needed!):

local router = require("ob:router")

ob.test("GET / renders the Mini Blog home page", function()
    local app = router.new()
        :static("/public", "public")
        :mount("/", "src/apps/posts/routes")

    local resp = app:handle({ method = "GET", path = "/", headers = {} })
    assert(resp.status == 200)
    assert(resp.body:find("Latest Posts", 1, true) ~= nil)
end)

ob.test("Static assets return ETag and 304 Not Modified", function()
    local app = router.new():static("/public", "public")

    local first = app:handle({ method = "GET", path = "/public/styles.css", headers = {} })
    assert(first.status == 200)
    assert(first.headers["ETag"] ~= nil)

    local cached = app:handle({
        method = "GET",
        path = "/public/styles.css",
        headers = { ["If-None-Match"] = first.headers["ETag"] },
    })
    assert(cached.status == 304)
end)

Run your test suite against an isolated in-memory SQLite database:

ORBITA_DB=:memory: ob test --allow-env=ORBITA_DB --allow-read=.

4. Deploy as a Single-File Binary

Configure [embed] in ob.toml so your routes, .html templates, and public/ assets are bundled into the executable:

[embed]
include = ["src", "public", "migrations"]

Compile the standalone binary:

ob build --compile src/main.tyl -o dist/mini-blog

Ship dist/mini-blog to any server and run it with 12-Factor environment variables — zero external runtime dependencies:

APP_ENV=production HOST=0.0.0.0 PORT=8080 ORBITA_DB=/var/data/blog.db ./dist/mini-blog

Previous: ← Part 4: Forms, Auth & Caching · Reference: Router Reference (ob:router) · HTML Templates Reference