This is the server-side app for Oneday, built in TypeScript, utilizing an Express server with WebSocket integration.
GET "/channels" : Channel[]
- returns a list of Channels stored on the server
GET "/channels/:id" : Channel
- returns a single Channel by id
POST "/channels/create" : Channel
- create a Channel with ChannelInput as JSON body
DELETE "/channels/:idOrName" : number
- deletes a channel by id or name, returning the number of channels deleted
GET "/channels/:channel/messages" : Message[]
- get all Messages by channel_id
socket.on("message": IncomingMessage): OutgoingMessage
- type "SUBSCRIBE":
- subscribe
usernameto channel, response with OutgoingMessage type INFO
- subscribe
- type "PUBLISH":
- store IncomingMessage to db as Message
- broadcast OutgoingMessage type MESSAGE to all subscribers
Channel
interface Channel {
id: string;
name: string;
description?: string;
location?: string;
created_at: string; // ISO8601 format
}ChannelInput
interface ChannelInput {
name: string;
description?: string;
location?: string;
}Message
interface Message {
id?: number;
channel_id: string;
username: string;
content: string;
created_at: string; // ISO 8601
}IncomingMessage (ws)
interface IncomingMessage {
type: "SUBSCRIBE" | "PUBLISH";
channel?: string; // displayed channel name
channel_id?: string; // uuid
username?: string;
content?: string;
}OutgoingMessage (ws)
interface OutgoingMessage {
type: "MESSAGE" | "INFO";
channel?: string;
channel_id?: string; // uuid
username?: string;
content?: string;
created_at?: string; // ISO 8601
message?: string;
}