http-nu 0.15.0

The surprisingly performant, Nushell-scriptable, cross.stream-powered, Datastar-ready HTTP server that fits in your back pocket.
Documentation
# http-nu examples hub
#
# Run: http-nu --datastar :3001 examples/serve.nu
# With store: http-nu --datastar --store ./store :3001 examples/serve.nu

use http-nu/router *
use http-nu/html *

let basic = source basic.nu
let stor_example = source stor.nu
let counter = source datastar-counter/serve.nu
let sdk = source datastar-sdk/serve.nu
let mermaid = source mermaid-editor/serve.nu
let templates = source templates/serve.nu
let quotes = source quotes/serve.nu
let blog = source blog/serve.nu

let has_store = $HTTP_NU.store != null

def example-link [href: string label: string desc: string --disabled] {
  if $disabled {
    LI (SPAN {style: {color: "#9ca3af"}} $label) $" --($desc) " (SPAN {style: {color: "#9ca3af" font-size: "0.85em"}} "(requires --store)")
  } else {
    LI (A {href: $href} $label) $" --($desc)"
  }
}

let routes = [
  (
    route {method: GET path: "/"} {|req ctx|
      HTML (
        HEAD
        (META {charset: "UTF-8"})
        (META {name: "viewport" content: "width=device-width, initial-scale=1"})
        (TITLE "http-nu examples")
        (STYLE "
body { font-family: system-ui, sans-serif; max-width: 600px; margin: 2rem auto; padding: 0 1rem; }
a { color: #2563eb; }
li { margin: 0.5rem 0; }
")
      ) (
        BODY
        (H1 "http-nu examples")
        (P (A {href: "https://github.com/cablehead/http-nu/tree/main/examples"} "source on GitHub"))
        (UL
          (example-link "./basic/" "basic" "minimal routes, JSON, streaming")
          (example-link "./stor/" "stor" "in-memory SQLite with stor")
          (example-link "./datastar-counter/" "datastar-counter" "reactive counter")
          (example-link "./datastar-sdk/" "datastar-sdk" "SDK feature demo")
          (example-link "./mermaid-editor/" "mermaid-editor" "live diagram editor")
          (example-link "./templates/" "templates" ".mj template modes")
          (example-link "./quotes/" "quotes" "live quotes board" --disabled=(not $has_store))
          (example-link "./blog/" "blog" "routing, layouts, HTML composition")
        )
      )
    }
  )

  (mount "/basic" $basic)
  (mount "/stor" $stor_example)
  (mount "/datastar-counter" $counter)
  (mount "/datastar-sdk" $sdk)
  (mount "/mermaid-editor" $mermaid)
  (mount "/templates" $templates)
  (mount "/blog" $blog)
  ...(if $has_store {
    [(mount "/quotes" $quotes)]
  } else {
    []
  })
]

{|req|
  dispatch $req $routes
}