A Simple Chat Server
Running on https://chat.kuljet.com
table messages { message : text, timestamp : timestamp }
serve get / =
let template = fun content ->
[ docType<html> [ <head> [ <link> { href = "/style.css", rel = "stylesheet" }
, <meta> { name = "viewport", content = "width=device-width, intial-scale=1" }
,
]<body> content
,
]
]in
let messagesHtml =
let query = (messages order timestamp desc limit 100) order timestamp asc in
<div> { class = "messages" }
select { message } -> <div> { class = "message" } message)
(query in
let formHtml =
let formAttrs = { method = "POST", action = "/msg", class = "inputForm" } in
let nameInput = <input> { name = "message", class = "inputMessage", autofocus = "true" } in
let submitInput = <input> { type = "submit" } in
<form> formAttrs [ nameInput, submitInput ]
in
template [ messagesHtml, formHtml ]
let insertMessage =
fun msg ->
insert messages { message = msg, timestamp = now }
serve post /msg =
fun formVars: { message: text } ->
then
insertMessage formVars.message "/"
redirect
serve get /style.css =
"text/css" "style.css" file