2024-09-23 15:45:20 +02:00
|
|
|
"#httpserver/base.spl" import
|
|
|
|
"#httpserver/static.spl" import
|
2024-09-19 20:59:04 +02:00
|
|
|
|
2024-10-14 16:29:13 +02:00
|
|
|
1024 64 * net:http:server:=bufsize
|
2024-10-14 16:41:16 +02:00
|
|
|
60 20 * net:http:server:=client-cache
|
2024-10-14 16:29:13 +02:00
|
|
|
|
2024-09-19 20:59:04 +02:00
|
|
|
func destub { html | with html title ;
|
|
|
|
stub.html
|
|
|
|
:replace<"+title" title>
|
|
|
|
:replace<"+body" html>
|
|
|
|
:replace<"Lorem ipsum" lorem-ipsum>
|
|
|
|
}
|
|
|
|
|
|
|
|
def lorem-ipsum "lorem-ipsum" read-file:replace<"\n" "<br>"> =lorem-ipsum
|
|
|
|
|
|
|
|
def stub.html "stub.html" read-file =stub.html
|
|
|
|
def 404.html "404.html" read-file destub<"404"> =404.html
|
|
|
|
|
|
|
|
def index.html "index.html" read-file destub<"Home"> =index.html
|
|
|
|
def features.html "features.html" read-file destub<"Features"> =features.html
|
|
|
|
|
|
|
|
func main { mega | with args ;
|
2024-10-14 16:59:33 +02:00
|
|
|
def server net:http:Server:new<"::0" 13130> =server
|
2024-09-19 20:59:04 +02:00
|
|
|
|
|
|
|
"server is listening on 13130" println;
|
|
|
|
|
|
|
|
while { 1 } {
|
|
|
|
server:accept { | with client ;
|
2024-09-19 21:33:47 +02:00
|
|
|
"got a request" println;
|
2024-09-19 20:59:04 +02:00
|
|
|
catch {
|
|
|
|
client:read;
|
|
|
|
|
|
|
|
client handle-client;
|
|
|
|
} { with err ;
|
|
|
|
"A request has errored out with " err:message concat println;
|
|
|
|
"at: " println;
|
|
|
|
&println err:trace:foreach;
|
|
|
|
}
|
|
|
|
} fork pop
|
|
|
|
}
|
|
|
|
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
|
|
|
func handle-client { | with client ;
|
2024-09-23 15:45:20 +02:00
|
|
|
client
|
|
|
|
:serve-html-string<index.html "/">
|
|
|
|
:serve-html-string<features.html "/features">
|
2024-10-14 16:41:16 +02:00
|
|
|
:serve-file<"style.css" "/style.css" "text/css">
|
2024-10-14 16:29:13 +02:00
|
|
|
:serve-file-cached<"screenshot_ingame.png" "/screenshots/ingame.png" "image/png">
|
|
|
|
:serve-file-cached<"screenshot_selection.png" "/screenshots/selection.png" "image/png">
|
|
|
|
:serve-file-cached<"screenshot_seedoverlay_generating.png" "/screenshots/seedoverlay/generating.png" "image/png">
|
|
|
|
:serve-file-cached<"screenshot_seedoverlay_hut.png" "/screenshots/seedoverlay/hut.png" "image/png">
|
|
|
|
:serve-file-cached<"screenshot_seedoverlay_underground.png" "/screenshots/seedoverlay/underground.png" "image/png">
|
2024-09-23 15:45:20 +02:00
|
|
|
:is-open
|
|
|
|
if {
|
|
|
|
404.html client:write-head<404 "Not found">:write-html-body:finish;
|
2024-09-19 20:59:04 +02:00
|
|
|
}
|
|
|
|
}
|
2024-09-23 15:45:20 +02:00
|
|
|
|