How-to Guides
fluxy.config.ts
Declarative room authz, middleware hooks, and client defaults with @fluxy-chat/config.
Use @fluxy-chat/config to declare per-room authorization, publish middleware, and client defaults — similar to a next.config for your chat deployment.
Example
import {
defineConfig,
allow,
block,
defineMiddleware,
allowPublish,
blockPublish,
} from "@fluxy-chat/config";
const moderate = defineMiddleware("publish", (ctx) => {
if (ctx.capabilities.publish === false) {
return blockPublish("You do not have permission to post.");
}
return allowPublish();
});
export default defineConfig({
workerUrl: process.env.FLUXY_WORKER_URL,
client: {
readOn: "visible",
wsCache: "on",
historyLimit: 50,
},
rooms: {
"support-*": {
anonymous: false,
authz: (ctx) =>
ctx.anonymous ? block("Sign in to contact support.") : allow({ publish: true }),
onPublish: [moderate.handler],
},
"room-*": {
anonymous: true,
authz: () => allow({ publish: true, invokeAgent: true }),
onPublish: [moderate.handler],
},
},
});Copy from packages/config/fluxy.config.example.ts in the monorepo.
Room patterns
| Pattern | Use case |
|---|---|
support-* | Authenticated support rooms |
room-* | Public demo rooms with agent invoke |
| Exact room id | Override for a single channel |
Middleware
defineMiddleware("publish", handler) runs before messages are accepted. Return blockPublish(reason) to reject with a user-visible error, or allowPublish() to continue.
Worker integration
The Worker reads fluxy.config.js (compiled from TypeScript) on self-host.
Hosted overlay (no forked Worker): GET/PUT /admin/projects/:id/publish-config stores deny-substrings, guestCanPublish, iotAutoAgentId, and rooms (anonymous, per-room deny, capabilities, extension slots). pnpm fluxy:deploy uploads fluxy.hosted.json. The publish pipeline runs file onPublish first, then these D1 rules. Put an agent handle in iotAutoAgentId to invokeAgent on each iot.reading without an @mention.
Room extension snapshots: client.getRoomExtensions(roomId) / setRoomExtension(roomId, id, { kind: "kv", data }). Hosted slots are declared kinds (kv | counter), not eval.