bunbun.dev/server.fnl

31 lines
763 B
Plaintext
Raw Normal View History

2024-05-20 20:23:38 -07:00
(local socket (require :socket))
2024-05-20 20:40:11 -07:00
(local ssl (require :ssl))
2024-05-20 20:23:38 -07:00
(local handle-client (. (require :client-handler) :handle-client))
(local port _G.port)
2024-05-20 20:23:38 -07:00
(local server (socket.tcp))
(server:bind "*" port)
(server:listen)
2024-05-20 20:40:11 -07:00
(local params {:mode "server"
:protocol "tlsv1_2"
:key "../privkey.pem"
:certificate "../fullchain.pem"
:cafile "../chain.pem"
:verify "none"
:options "all"})
2024-05-20 20:23:38 -07:00
(while true
2024-05-20 20:40:11 -07:00
(var client (server:accept))
(set (_G.client-address _G.client-port) (client:getpeername))
2024-05-20 20:23:38 -07:00
(when (not _G.use-http)
(set client (ssl.wrap client params))
(client:dohandshake))
2024-05-20 20:23:38 -07:00
2024-05-20 20:40:11 -07:00
(let [co (coroutine.create (fn [] (handle-client client)))]
(coroutine.resume co)))