62 lines
1.9 KiB
Text
62 lines
1.9 KiB
Text
"#httpserver/base.spl" import
|
|
"#httpserver/static.spl" import
|
|
|
|
1024 64 * net:http:server:=bufsize
|
|
60 60 6 * * net:http:server:=client-cache
|
|
|
|
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 ;
|
|
def server net:http:Server:new<"::0" 13130> =server
|
|
|
|
"server is listening on 13130" println;
|
|
|
|
while { 1 } {
|
|
server:accept { | with client ;
|
|
"got a request" println;
|
|
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 ;
|
|
client
|
|
:serve-html-string<index.html "/">
|
|
:serve-html-string<features.html "/features">
|
|
:serve-file<"style.css" "/style.css" "text/css">
|
|
: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">
|
|
:serve-file-cached<"screenshot_gui.png" "/screenshots/gui.png" "image/png">
|
|
:serve-file-cached<"Monocraft.ttf" "/Monocraft.ttf" "font/ttf">
|
|
:is-open
|
|
if {
|
|
404.html client:write-head<404 "Not found">:write-html-body:finish;
|
|
}
|
|
}
|
|
|