import { BaseHandler, defineApp, page, SocketRoute, type RedWebSocket } from 'redweb';

@page('/', { live: false })
class HomePage {
    render() { return <h1>Hello from HTTP!</h1>; }
}

class Hello extends BaseHandler {
    constructor() { super('hello'); }
    onMessage(socket: RedWebSocket) {
        socket.sendJson({ type: 'hello', message: 'Hello from WebSockets!' });
    }
}

class ChatRoute extends SocketRoute {
    constructor() { super({ path: '/chat', handlers: [Hello] }); }
}

const app = defineApp({ pages: [HomePage], sockets: [ChatRoute] });

await app.run();
