Skip to content
Browse documentation
typescript sdk

Run an HTTP service

Mount a checked Service on Elysia and make server startup and resource ownership explicit.

Choose one server owner

The managed helper owns the listener. Configure native Elysia hooks/plugins in createApp and mount Services in setup. statusService is the implementation from the contracts guide.

// target/server/main.ts
import { Elysia } from "elysia";
import { mountService } from "@smoothie-framework/service-elysia";
import { createServer } from "@smoothie-framework/service-elysia/server";
import { statusService } from "./status";

const server = createServer({
  port: 3000,
  createApp: () => new Elysia(),
  setup({ app }) {
    mountService(app, statusService, { maxRequestBytes: 4096 });
  },
});
await server.start();
// On the target's shutdown path: await server.stop();

Mount only the boundary you intend

Protect operations with request admission before body parsing. Login, CORS preflight, public health endpoints and webhooks keep their own native scopes. Do not place body-consuming middleware before bounded Service parsing.

Acquire owned dependencies through setup's resources helper when rollback and reverse cleanup are needed. Injected dependencies remain borrowed unless registered for disposal.

Embedding is valid: mountService also accepts an existing native Elysia application. Its host then owns the listener. Hosting a Service does not install a page router or make the entire application portable.