Quickstart: mount, create, redirect
Quickstart
Section titled “Quickstart”bun add @xtandard/links # or npm i / pnpm add / yarn addMount the admin panel and the redirect handler in a Hono app (Elysia, Express, Bun and Next.js are the same two lines — see Adapters):
import { Hono } from "hono";import { createLinksCore } from "@xtandard/links";import { linksPanel, linksRedirect } from "@xtandard/links/hono";import { createSqliteStorage } from "@xtandard/links/storage/sqlite";
const core = createLinksCore({ storage: createSqliteStorage({ path: "links.db" }), defaultDomain: "localhost",});
const app = new Hono();app.route("/links", linksPanel({ core, basePath: "/links" })); // admin UI + APIapp.use("*", linksRedirect({ core })); // GET /{slug} → redirect; everything else falls throughexport default app;Open http://localhost:3000/links for the dashboard. With no auth the panel is open — fine on
localhost, not in production: see Auth and Authorization.
Prefer no code? STORAGE_DRIVER=sqlite bunx @xtandard/links serve runs the same panel and
redirects, or use the Docker image (see Deployment).
Create your first link
Section titled “Create your first link”const link = await core.createLink({ url: "https://acme.com/pricing", slug: "pricing", // omit for a generated 7-character slug tags: ["launch"], utm: { source: "newsletter", campaign: "spring" },});// → https://localhost/pricing redirects to https://acme.com/pricing?utm_source=newsletter&utm_campaign=springLinks belong to a tenant (default "default") and live on a domain. Register your branded
domains once (DNS and TLS are your edge’s job) and give tenants their own:
await core.createDomain({ hostname: "go.acme.com", isDefault: true, notFoundUrl: "https://acme.com",});await core.createDomain({ hostname: "links.customer.com", tenant: "customer-42" });
await core.createLink({ tenant: "customer-42", url: "https://customer.com/sale", slug: "sale" });// → https://links.customer.com/saleEverything else a link can do — expiry (expiresAt, expiredUrl, maxClicks), password, link
previews (preview: { title, description, image } served to Slack, X, iMessage…), redirectStatus,
query pass-through, externalId for idempotent upserts, QR codes, bulk CSV import — is in
Links.