poweredBy
Middleware for adding an X-Powered-By header to HTTP responses. This is commonly used to indicate the server or framework powering the application.
Import
import { poweredBy } from "tezx/middleware";Parameters
const poweredBy = (serverName?: string): Middleware => { ... }-
serverName(optional) – A custom server name to use in the header.- Default:
"TezX"
- Default:
Usage
Basic Usage
Adds the default X-Powered-By header with value "TezX":
import { poweredBy } from "tezx/middleware";
app.use(poweredBy());- Response Header Example:
X-Powered-By: TezXCustom Server Name
app.use(poweredBy("MyServer"));- Response Header Example:
X-Powered-By: MyServerMiddleware Type
function poweredBy(serverName?: string): Middleware- Returns a
Middlewarefunction compatible with TezX. - Can be used globally or per route.
Example with TezX Routes
import poweredBy from "tezx/middleware/poweredBy";
// Set global X-Powered-By header
app.use(poweredBy());
// Sample route
app.get("/api/data", async (ctx) => {
return ctx.json({ message: "Hello World" });
});
// Override with custom server name for a specific route
app.get("/api/custom", poweredBy("CustomServer"), async (ctx) => {
return ctx.json({ message: "Custom Header Applied" });
});/api/dataresponse header:X-Powered-By: TezX/api/customresponse header:X-Powered-By: CustomServer
paginationHandler
The paginationHandler middleware provides automatic pagination handling for API endpoints. It simplifies extracting pagination parameters, calculating offsets, generating metadata, and optionally integrates with a dynamic data source (e.g., database, ORM).
rateLimiter
The rateLimiter is a middleware for request throttling. It enforces maximum request limits per client using a sliding window and supports custom client identification, custom storage, and custom error handling.