Public
Remixed
Basic HTML starter template based on Glitch's starter
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

💬 Real-Time Support Chat

A multi-user real-time chat app built on Val Town with persistent message history.

Features

  • Username join gate — users pick a unique username before entering chat
  • Real-time messaging — Server-Sent Events (SSE) push new messages to all connected clients instantly
  • Persistent history — messages are stored in SQLite and loaded on page reload
  • Online user list — sidebar shows who's currently connected
  • Join/leave notifications — system messages when users enter or leave
  • Validation — empty usernames, empty messages, duplicate usernames, and oversized messages are all rejected with clear error messages
  • Multi-tab support — open in multiple browser tabs with different usernames to test

Architecture

Rendering mermaid diagram...

API Endpoints

MethodPathDescription
POST/api/joinValidate & claim a username
GET/api/stream?username=SSE stream for real-time events
GET/api/messagesFetch chat history (last 200)
POST/api/messagesSend a new message

Files

  • main.tsx — HTTP server with API routes, SSE streaming, BroadcastChannel
  • index.html — Join screen + chat UI
  • script.js — Client-side logic (SSE client, form handling)
  • style.css — Chat layout and styling