gaman@0.0.21
Release Notes: v0.0.21
Patch Changes
In this release, significant updates and enhancements have been implemented:
Key Features
-
WebSocket Block
- Now you can define WebSocket functionality directly in a block using the new
websocketproperty. - Example:
import { defineBlock } from "gaman"; export default defineBlock({ path: "/ws", websocket: (ctx) => { return { onMessage: (message) => { ctx.send(`Received: ${message}`); }, }; }, });
- Supports events like
onOpen,onClose,onMessage,onError, and more.
- Now you can define WebSocket functionality directly in a block using the new
-
Middleware Enhancements
- Middleware can now be included at the block level using the
includesproperty. - Example:
import { defineBlock, cors } from "gaman"; export default defineBlock({ path: "/api", includes: [cors({ origin: "*" })], routes: { "/example": (ctx) => { return Response.json({ message: "CORS enabled!" }); }, }, });
- Custom middleware is supported via
defineMiddleware.import { defineMiddleware, next } from "gaman"; export default defineMiddleware((ctx) => { console.log("Custom middleware executed"); return next(); });
- Middleware can now be included at the block level using the
-
Logging Improvements
- Enhanced logging with detailed information such as:
- Response time in milliseconds.
- Status codes.
- Path accessed.
- This makes debugging and performance tracking easier.
- Enhanced logging with detailed information such as:
- New Built-in Packages
- Added built-in middleware packages:
cors: For Cross-Origin Resource Sharing configuration.basic-auth: For HTTP Basic Authentication.
- Added built-in middleware packages:
Example Usage
WebSocket
Define WebSocket in a block:
import { defineBlock } from "gaman";
export default defineBlock({
path: "/chat",
websocket: (ctx) => {
return {
onMessage: (message) => {
ctx.send(`You said: ${message}`);
},
};
},
});