[!WARNING] This is Mesh. A fast web framework based on uWebSocket.js
[!NOTE] The project was renamed from Fiber to Mesh to avoid confusion with other Web Framework project
µWebSockets.js is a web server bypass for Node.js that reimplements eventing, networking, encryption, web protocols, routing and pub/sub in highly optimized C++. As such, µWebSockets.js delivers web serving for Node.js, 8.5x that of Fastify and at least 10x that of Socket.IO. It is also the built-in web server of Bun.
npm i @ionited/mesh
import { App } from '@ionited/mesh';
const app = new App();
app
.use((req, res) => console.log('Hello World!'))
.catch((e, req, res) => res.status(e.status ?? 500).json({ message: e.message ?? 'Internal server error' }))
.notFound((req, res) => res.status(404).end())
.any('/users', (req, res) => res.json({ success: true }))
.del('/users', (req, res) => res.json({ success: true }))
.get('/users', (req, res) => res.json({ success: true }))
.options('/users', (req, res) => res.json({ success: true }))
.post('/users', (req, res) => res.json({ success: true }))
.put('/users', (req, res) => res.json({ success: true }))
.ws('/ws', {
close: (ws, code, message) => {},
message: (ws, message) => {},
open: ws => {}
})
.listen(1000);
import { Router } from '@ionited/mesh';
const router = new Router('/public');
router
.use((req, res) => console.log('Hello World!'))
.any('/users', (req, res) => res.json({ success: true }))
.del('/users', (req, res) => res.json({ success: true }))
.get('/users', (req, res) => res.json({ success: true }))
.options('/users', (req, res) => res.json({ success: true }))
.post('/users', (req, res) => res.json({ success: true }))
.put('/users', (req, res) => res.json({ success: true }))
.ws('/ws', {
close: (ws, code, message) => {},
message: (ws, message) => {},
open: ws => {}
});
const routes = router.routes();
app.routes(routes);
interface HttpRequest {
body(): Promise<{ [key: string]: any }>;
data: { [key: string]: any };
files(): Promise<{ [key: string]: UploadedFile | undefined }>;
headers(): { [key: string]: string };
method(): string;
params(): { [key: string]: string };
query(): { [key: string]: any };
route: string;
url(): string;
}
interface HttpResponse {
end(text?: string): void;
header(key: string, value: string): this;
json(json: any): void;
send(text: string): void;
sendFile(path: string): Promise<void>;
status(status: number): this;
}
interface UploadedFile {
data: ArrayBuffer;
filename: string;
type: string;
}
interface WebSocket {
send(message: string): void;
}
export interface WebSocketBehavior {
close?: (ws: WebSocket, code: number, message: ArrayBuffer) => void;
message?: (ws: WebSocket, message: ArrayBuffer) => void;
open?: (ws: WebSocket) => void;
}
Copyright (c) 2023 Ion. Licensed under MIT License.