Server Routes
The entry point
Fulgur reads a single file: src/route.server.ts. This file must export default an Elysia instance. It is your API composition root — you decide what gets mounted and in what order.
// src/route.server.ts
import { Elysia } from "fulgur/server";
import { usersRoutes } from "./api/users.server";
import { postsRoutes } from "./api/posts.server";
const app = new Elysia().use(usersRoutes).use(postsRoutes);
export default app;
export type App = typeof app;INFO
The export type App = typeof app line is what powers type-safe Eden clients. See Client API.
Creating route modules
Individual route files are plain Elysia instances with named exports. They are not auto-discovered — you import and mount them yourself in route.server.ts.
// src/api/users.server.ts
import { Elysia } from "fulgur/server";
export const usersRoutes = new Elysia().get("/users", () => [
{ id: 1, name: "Alice" },
]);Two rules:
- The file must be named
*.server.ts - It must export a named constant that is an
Elysiainstance
Using Elysia features
fulgur/server is a direct re-export of elysia. Everything available in Elysia works here:
import { Elysia, t } from "fulgur/server";
export const usersRoutes = new Elysia().post(
"/users",
({ body }) => ({ created: body.name }),
{
body: t.Object({
name: t.String(),
}),
},
);Grouping routes
Use Elysia's .group() to add a prefix to a set of routes:
import { Elysia } from "fulgur/server";
export const adminRoutes = new Elysia({ prefix: "/admin" })
.get("/stats", () => ({ users: 42 }))
.get("/logs", () => []);Routes will be available at /api/admin/stats and /api/admin/logs.
Nested composition
You can compose route modules inside other route modules before mounting them in route.server.ts:
// src/api/v1.server.ts
import { Elysia } from "fulgur/server";
import { usersRoutes } from "./users.server";
import { postsRoutes } from "./posts.server";
export const v1Routes = new Elysia({ prefix: "/v1" })
.use(usersRoutes)
.use(postsRoutes);// src/route.server.ts
import { Elysia } from "fulgur/server";
import { v1Routes } from "./api/v1.server";
export default new Elysia().use(v1Routes);
export type App = typeof app; // ← TS infers the full nested typeHot reload
In development, Fulgur watches for changes to any *.server.ts file. When a change is detected, the backend process restarts automatically. No manual restart needed.
Server file protection
Fulgur's Vite plugin blocks any runtime import of *.server.ts files from client code:
import { usersRoutes } from "./api/users.server";
// ✗ Error: Cannot import server module in client codeType-only imports (import type) are safe and stripped at build time.
