Config - ElysiaJS | ElysiaJS

ID: 2118https://elysiajs.com/patterns/configuration.html
Source

Config

Elysia comes with a configurable behavior, allowing us to customize various aspects of its functionality.

We can define a configuration by using a constructor.

import { Elysia, t } from 'elysia'

new Elysia({
  prefix: '/v1',
  normalize: true
})

adapter

Since 1.1.11

Runtime adapter for using Elysia in different environments.
Default to appropriate adapter based on the environment.

import { Elysia, t } from 'elysia'
import { BunAdapter } from 'elysia/adapter/bun'

new Elysia({
  adapter: BunAdapter
})

allowUnsafeValidationDetails

Since 1.4.13

Whether Elysia should include unsafe validation details in the error response on production.

import { Elysia, t } from 'elysia'

new Elysia({
  allowUnsafeValidationDetails: true
})

By default, Elysia will omit all validation detail on production.
This is done to prevent leaking sensitive information about the validation schema, such as field names and expected types, which could be exploited by an attacker.
Ideally, this should only be enabled on public APIs as it may leak sensitive information about the server implementation.

Options – @default false
  • true – Include unsafe validation details in the error response on production
  • false – Exclude unsafe validation details in the error response on production

aot

Since 0.4.0

Ahead of Time compilation.
Elysia has a built‑in JIT “compiler” that can optimize performance.

import { Elysia } from 'elysia'

new Elysia({
  aot: true
})
Options – @default false
  • true – Precompile every route before starting the server
  • false – Disable JIT entirely. Faster startup time without cost of performance

detail

Define an OpenAPI schema for all routes of an instance.
This schema will be used to generate OpenAPI documentation for all routes of an instance.

import { Elysia } from 'elysia'

new Elysia({
  detail: {
    hide: true,
    tags: ['elysia']
  }
})

encodeSchema

Handle custom t.Transform schema with custom Encode before returning the response to client.
This allows us to create custom encode function for your data before sending response to the client.

import { Elysia, t } from 'elysia'

new Elysia({ encodeSchema: true })
Options – @default true
  • true – Run Encode before sending the response to client
  • false – Skip Encode entirely

name

Define a name of an instance which is used for debugging and Plugin Deduplication.

import { Elysia } from 'elysia'

new Elysia({
  name: 'service.thing'
})

nativeStaticResponse

Since 1.1.11

Use an optimized function for handling inline value for each respective runtime.

import { Elysia } from 'elysia'

new Elysia({
  nativeStaticResponse: true
})

(Further configuration options continue beyond this excerpt.)