import { CodeBlock } from "../../components/CodeBlock.tsx"; import { CodeWindow } from "../../components/CodeWindow.tsx"; import { PageSection } from "../../components/PageSection.tsx"; import { SideBySide } from "../../components/SideBySide.tsx"; import { SectionHeading } from "../../components/homepage/SectionHeading.tsx"; import { FancyLink } from "../../components/FancyLink.tsx"; const wsCode = `import { App } from "fresh"; const app = new App(); app.ws("/chat", { open(socket) { console.log("Client connected"); }, message(socket, event) { // Echo the message back socket.send(\`You said: \${event.data}\`); }, close(socket) { console.log("Client disconnected"); }, }); app.listen();`; export function WebSocketSection() { return (
First-class WebSockets

Add real-time endpoints with{" "} app.ws() {" "} — define open, message, and close handlers in a single object. Build chat, live dashboards, or collaborative editing without leaving Fresh.

Learn about WebSockets
); }