App
The Lynx
class is used to create your application.
Methods
:<method>
:<method>(path: string, handler: Handler | Middleware, ...: Handler | Middleware)
Supported methods: :get
, :post
, :put
, :delete
, :patch
Define a route for a specific HTTP method.
:all
:all(path: string, handler: Handler | Middleware, ...: Handler | Middleware)
Define a route that matches all HTTP methods.
:on
:on(method: string, path: string, handler: Handler | Middleware, ...: Handler | Middleware)
Define a route for a specific or custom HTTP method.
:use
:use(middleware: Middleware, ...: Middleware)
or
:use(path: string, middleware: Middleware, ...: Middleware)
Create a middleware that runs on every request or on a specific path.
:static
:static(path: string, directory: string)
Serve static files from a directory.
:route
:route(path: string, app: Lynx)
Mount a sub-application at a specific path.
:notFound
:notFound(handler: Handler)
Define a custom 404 handler.
:onError
:onError(handler: ErrorHandler)
Define a custom error handler.
:request
:request(request: string | net.ServeRequest)
Send a request to the application and return the response. This can be useful for testing your application.
Alternatively, you can pass a net.ServeRequest
object.
:serve
:serve(port: number?)
Start serving the application. Optionally specify a port (default: 3000).