PORT environment variable; maybe non-blocking

Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
Skylar "The Cobra" Widulski 2023-12-07 14:02:12 -05:00
parent b174194068
commit f7ebc53e96
Signed by: cobra
GPG Key ID: 4FD8F812083FF6F9
1 changed files with 11 additions and 3 deletions

View File

@ -23,9 +23,12 @@
#:use-module (web uri)
#:use-module (web request)
#:use-module (web http)
#:use-module (ice-9 suspendable-ports)
#:use-module (ice-9 textual-ports)
#:use-module (ice-9 binary-ports))
(install-suspendable-ports!)
(define (handler request request-body)
(let ((uri (request-uri request))
(path (uri-path (request-uri request)))
@ -84,6 +87,11 @@
(meme-page path))
(else (error-page 404)))))
(run-server handler 'http '(#:port 8003
#:addr 0))
(define sock (socket PF_INET SOCK_STREAM 0))
(let ((port (if (getenv "PORT")
(string->number (getenv "PORT"))
8003)))
(bind sock AF_INET INADDR_ANY port)
(fcntl sock F_SETFL (logior O_NONBLOCK
(fcntl sock F_GETFL)))
(run-server handler 'http `(#:socket ,sock)))