Types
Lunatic framework types and interfaces that can be imported.
Interfaces
CorsOptions
CORS middleware options.
export interface CorsOptions {
allowedHeaders?: string | string[]
corsErrorStatus?: number
credentials?: boolean
exposedHeaders?: string | string[]
maxAge?: number
methods?: HttpMethod | HttpMethod[]
origin?:
| boolean
| string
| string[]
| RegExp
| RegExp[]
| ((origin: string) => boolean)
preflightSuccessStatus?: number
}
ServeStaticOptions
serveStatic
middleware options.
export interface ServeStaticOptions {
dotfiles?: 'allow' | 'forbid' | 'ignore'
etag?: boolean
index?: string | false
lastModified?: boolean
}
UploadedFile
File uploaded via form.
export interface UploadedFile {
data: Buffer
filename: string
mimetype: string
}
See formParser
Types
ApplicationFeature
Application features that can be enabled, disabled and toggled.
export type ApplicationFeature =
| '500-on-error'
| 'auto-head-handler'
| 'x-powered-by'
See App features
CookieOptions
Object representation of Set-Cookie
header attributes.
See
Response.setCookie
.
export type CookieOptions = {
domain?: string
expires?: string | number
httpOnly?: boolean
maxAge?: number
path?: string
} & (
| {
sameSite?: 'None'
secure: true
}
| {
sameSite?: 'Lax' | 'Strict'
secure?: boolean
}
)
HttpMethod
HTTP request method.
export type HttpMethod =
| 'GET'
| 'HEAD'
| 'POST'
| 'PUT'
| 'DELETE'
| 'CONNECT'
| 'OPTIONS'
| 'TRACE'
| 'PATCH'
| '*'
See Routing
NextHandler
Next middleware. To call next middleware, call next()
- function of this type, which is 3rd parameter of RequestHandler
.
export type NextHandler = () => void
See Routing
RenderFunction
Render function, used to render HTML templates.
export type RenderFunction = (
source: string,
options?: Record<string, any>,
) => string
See: Template engines
RequestHandler
Request handler function.
export type RequestHandler = (
req: Request,
res: Response,
next: NextHandler,
) => unknown
See: Request, NextHandler