SvelteKit
Use Silgi with SvelteKit API routes — catch-all endpoint with full type safety.
SvelteKit uses file-based API routes. Silgi integrates via a catch-all +server.ts.
Setup
// src/routes/api/[...path]/+server.ts
import { } from 'silgi/sveltekit'
import { } from '$lib/server/rpc'
const = (, {
: () => ({
: getDB(),
: .locals.user,
}),
})
export const =
export const = Context from SvelteKit hooks
Use SvelteKit's handle hook to set event.locals, then access in the context factory:
// src/hooks.server.ts
export async function ({ , }) {
.locals.user = await getUser(.cookies.get('session'))
return ()
}// src/routes/api/[...path]/+server.ts
const = createHandler(appRouter, {
: () => ({
: .locals.user,
}),
})Analytics and Scalar
Enable the built-in analytics dashboard or Scalar API reference directly in the adapter:
const = createHandler(appRouter, {
: () => ({ : .locals.user }),
: {
: process.env.ANALYTICS_TOKEN,
},
: true,
})The analytics dashboard is available at /api/analytics and Scalar at /api/reference.
What's next?
- Analytics — built-in monitoring dashboard
- Server — standalone
serve()as an alternative - Integrations — other available integrations