All docsSearch docs

Start

  1. 01Getting started
  2. 02Install
  3. 03Tracking

Features

  1. 04The dashboard
  2. 05Goals
  3. 06Short links
  4. 07AI sources and agents
  5. 08Email reports
  6. 09Scheduled check
  7. 10Ask your AI

Reference

  1. 11Performance
  2. 12Configuration
  3. 13HTTP API

Platforms

  1. 14Standalone server
  2. 15ClickHouse
  3. 16PHP
  4. 17WordPress
  5. 18Drupal
  6. 19Craft CMS
  7. 20Webflow
  8. 21Python
  9. 22Rails
  10. 23Ruby
  11. 24Go
  12. 25Java
  13. 26.NET
  14. 27Elixir
  15. 28Rust

Trust

  1. 29Privacy

Start

Install

Mount Runlight in Next.js, Nuxt, SvelteKit, Astro, Remix, Express, NestJS, Fastify, Koa, Hono, Bun, Deno, or Cloudflare Workers, or find the guide for your language.

Every install needs an instance (see Getting started), its routes mounted under /runlight, and the script tag on your pages. Only the routes change between frameworks.

rl.routes() returns a Fetch handler, handler(request), plus the same function under each method name, so any framework built on web Request and Response can use it directly. Change the path with rl.routes({ basePath: "/stats" }), and the script tag becomes /stats/s.js.

Next.js

In the App Router, add a catch-all route.

app/runlight/[[...path]]/route.ts

import { rl } from "@/lib/runlight";

export const { GET, POST, PUT, PATCH, DELETE, OPTIONS } = rl.routes();

Add the script to your root layout.

app/layout.tsx

<head>
  <script defer src="/runlight/s.js"></script>
</head>

Runlight needs the Node runtime, because it uses SQLite, Postgres, or MySQL. That is the default for route handlers.

Express and plain Node

@runlight/sdk/node adapts the handler to Node’s http module, and so to Express, Connect, and Koa (through ctx.req and ctx.res).

server.ts

import express from "express";
import { toNodeHandler, observer, shortLinks } from "@runlight/sdk/node";
import { rl } from "./runlight.js";

const app = express();
app.use(shortLinks(rl)); // short links at /go and on custom domains
app.use(observer(rl)); // AI agents reading your pages; optional
app.use(toNodeHandler(rl.routes().handler));

The adapter can go before or after any body parser, because it also reads a body that Express has already parsed, and it leaves the bodies of your app’s own requests unread. shortLinks goes before your own routes, so a link domain reaches Runlight first.

NestJS

Nest runs on Express by default, so the same middleware goes in main.ts, before listen.

src/main.ts

import { NestFactory } from "@nestjs/core";
import { toNodeHandler } from "@runlight/sdk/node";
import { AppModule } from "./app.module";
import { rl } from "./runlight";

const app = await NestFactory.create(AppModule);
app.use(toNodeHandler(rl.routes().handler));
await app.listen(3000);

Add app.use(shortLinks(rl)) before it for short links.

Fastify

Fastify reads request bodies itself, so give Runlight its own plugin scope with no body parsers, and hand it the raw request.

ts

import Fastify from "fastify";
import { toNodeHandler } from "@runlight/sdk/node";
import { rl } from "./runlight.js";

const app = Fastify();
const runlight = toNodeHandler(rl.routes().handler);

app.register(async (scope) => {
  scope.removeAllContentTypeParsers();
  scope.addContentTypeParser("*", (_req, _payload, done) => done(null));
  scope.all("/runlight", (req, reply) => { reply.hijack(); return runlight(req.raw, reply.raw); });
  scope.all("/runlight/*", (req, reply) => { reply.hijack(); return runlight(req.raw, reply.raw); });
});

Short links go in an onRequest hook, as Short links shows.

Koa

ts

import Koa from "koa";
import { toNodeHandler } from "@runlight/sdk/node";
import { rl } from "./runlight.js";

const app = new Koa();
const runlight = toNodeHandler(rl.routes().handler);

app.use(async (ctx, next) => {
  if (ctx.path !== "/runlight" && !ctx.path.startsWith("/runlight/")) return next();
  ctx.respond = false;
  await runlight(ctx.req, ctx.res);
});

For short links, add the middleware under Short links before this one.

Hono

ts

import { Hono } from "hono";
import { rl } from "./runlight";

const app = new Hono();
const runlight = rl.routes().handler;
app.all("/runlight/*", (c) => runlight(c.req.raw));
app.all("/runlight", (c) => runlight(c.req.raw));

Nuxt and Nitro

Put the instance in server/utils/runlight.ts (Nitro imports everything there for you), then add this route.

server/routes/runlight/[...path].ts

export default defineEventHandler((event) => rl.routes().handler(toWebRequest(event)));

Add the same file as server/routes/runlight.ts so /runlight itself answers too. The script tag goes in app.head in nuxt.config.ts.

nuxt.config.ts

export default defineNuxtConfig({
  app: { head: { script: [{ src: "/runlight/s.js", defer: true }] } },
});

SvelteKit

src/routes/runlight/[...path]/+server.ts

import { rl } from "$lib/runlight";

const { handler } = rl.routes();
export const GET = ({ request }) => handler(request);
export const POST = GET;
export const PUT = GET;
export const PATCH = GET;
export const DELETE = GET;
export const OPTIONS = GET;

Astro

Astro needs an adapter for server output.

src/pages/runlight/[...path].ts

import { rl } from "../../lib/runlight";

export const prerender = false;
export const ALL = ({ request }) => rl.routes().handler(request);

Remix and React Router

app/routes/runlight.$.ts

import { rl } from "~/runlight.server";

const { handler } = rl.routes();
export const loader = ({ request }) => handler(request);
export const action = ({ request }) => handler(request);

Bun

Bun cannot load better-sqlite3, so use its built-in SQLite through @runlight/sdk/bun.

server.ts

import { runlight } from "@runlight/sdk";
import { bunSqlite } from "@runlight/sdk/bun";

const rl = runlight({ store: bunSqlite({ path: "./data/runlight.db" }), site: { hostnames: ["example.com"] } });
const runlightRoutes = rl.routes().handler;

Bun.serve({
  port: 3000,
  fetch(request) {
    const { pathname } = new URL(request.url);
    if (pathname === "/runlight" || pathname.startsWith("/runlight/")) return runlightRoutes(request);
    return new Response("Your app");
  },
});

Elysia and other Bun frameworks pass request the same way.

Deno

Deno serves web Requests directly. Use libSQL (a local file or Turso) or Postgres for the store.

main.ts

import { runlight } from "npm:@runlight/sdk";
import { libsql } from "npm:@runlight/sdk/libsql";
import { createClient } from "npm:@libsql/client";

const rl = runlight({ store: libsql({ client: createClient({ url: "file:runlight.db" }) }), site: { hostnames: ["example.com"] } });
const runlightRoutes = rl.routes().handler;

Deno.serve((request) => {
  const { pathname } = new URL(request.url);
  if (pathname === "/runlight" || pathname.startsWith("/runlight/")) return runlightRoutes(request);
  return new Response("Your app");
});

Cloudflare Workers

Workers have no disk, so store the data in D1. Location comes from Cloudflare’s own headers with no setup. A Worker passes no connection address, so Runlight believes them with trustProxy left unset.

src/index.ts

import { runlight } from "@runlight/sdk";
import { d1 } from "@runlight/sdk/d1";

let routes: ReturnType<ReturnType<typeof runlight>["routes"]> | undefined;

export default {
  fetch(request: Request, env: { DB: D1Database; RUNLIGHT_TOKEN: string }) {
    // Made once per Worker instance, so the tables are checked when the instance starts.
    routes ??= runlight({ store: d1({ database: env.DB }), site: { hostnames: ["example.com"] } }).routes({ token: env.RUNLIGHT_TOKEN });
    return routes.handler(request);
  },
};

A Worker keeps its secrets in env, which Runlight cannot read by itself, so pass the token to routes() as above. Set it with wrangler secret put RUNLIGHT_TOKEN.

Route only /runlight/* to this Worker (or check the path first, as in the Bun example), and schedule the hourly check with a Cron Trigger that calls rl.check().

Anything else

If your server gives you a web Request, pass it to rl.routes().handler and return the Response. If it gives you Node’s req and res, use toNodeHandler from @runlight/sdk/node.

Other languages

Runlight comes in each of these languages, with the same dashboard and the same tables. Each page has the install, the routes for its frameworks, the scheduled check, and what differs from the TypeScript library.

Language Install Runs in
PHP composer require runlight/runlight Laravel, Symfony, plain PHP, and a drop-in for a domain of its own
Python pip install runlight Django, Flask, FastAPI, and any WSGI or ASGI app
Rails bundle add runlight Rails 8.0 and 8.1, through an engine and a generator
Ruby bundle add runlight sqlite3 Sinatra, Hanami, Roda, and any other Rack app
Go go get runlight.sh/go net/http, chi, Echo, and any router that takes an http.Handler
Java sh.runlight:runlight from Maven Central The JDK’s own server, servlet containers, and Spring Boot
.NET dotnet add package Runlight.AspNetCore ASP.NET Core and any other .NET app
Elixir {:runlight, "~> 0.5"} in mix.exs Phoenix and any Plug app
Rust cargo add runlight runlight-sqlx axum, hyper, and any server that takes a tower service

Every language except Elixir and Rust also has a standalone server of its own, and the standalone server page covers the Node one.

Behind a proxy

Runlight reads the visitor’s address from the last entry in X-Forwarded-For, the one your proxy adds, then from X-Real-IP or CF-Connecting-IP. By default it believes those headers only on a connection from this computer or a private network, where proxies and load balancers connect from. A client that reaches your app straight from the internet cannot choose its own address, so an app with no proxy in front needs no setting.

A Next.js route handler, Hono, Bun, and the other mounts that hand Runlight only the Request pass no connection address. There Runlight believes the headers on a hosting platform it knows (Vercel, Netlify, Cloudflare, AWS Lambda, Cloud Run, Azure, Fly, Render, Railway, Deno Deploy, or Heroku), and anywhere NODE_ENV is not production. In production anywhere else, such as next start behind your own nginx or Caddy, set trustProxy: true or the name of the header your proxy sets, or pass the connection’s address as handler(request, { ip }). Until you do, Runlight warns once and every visitor with the same browser counts as one. The Node adapter and the standalone server pass the connection’s address, so they need none of this.

When a CDN or proxy connects to your app from public addresses, such as Cloudflare in front of your server with nothing between, set trustProxy: "cf-connecting-ip" or trustProxy: true, or every visitor shows the proxy’s address. Runlight warns once when it sees forwarding headers it did not believe.

When a request passes through two proxies, such as Cloudflare in front of nginx, name the header that holds the visitor’s own address, like trustProxy: "cf-connecting-ip". The address is used for the daily visitor hash and the location lookup, and the rate limit uses a hash of it. It is never stored.

trustProxy: false never believes the headers. Runlight then also ignores the host’s location headers, so use geo for the country.