begin SimpleServer impl
This commit is contained in:
parent
dd3f36bb2a
commit
0f32cfa9b8
2 changed files with 91 additions and 0 deletions
21
SimpleServer/index.html
Normal file
21
SimpleServer/index.html
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<head>
|
||||||
|
<meta name=viewport content="width=device-width height=device-height">
|
||||||
|
<title>BaseBand download server</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>BaseBand downloads</h1>
|
||||||
|
|
||||||
|
This website serves the version information and downloads of BaseBand.
|
||||||
|
|
||||||
|
<h2>Artifacts</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="/download/client/release">/download/client/release</a></li>
|
||||||
|
<li><a href="/download/client/main">/download/client/main</a></li>
|
||||||
|
<li><a href="/download/loader">/download/loader</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Version information</h2>
|
||||||
|
|
||||||
|
<a href="/latest">/latest</a>
|
||||||
|
</body>
|
70
SimpleServer/server.spl
Normal file
70
SimpleServer/server.spl
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
|
||||||
|
"#httpserver/base.spl" import
|
||||||
|
"#httpserver/static.spl" import
|
||||||
|
use net:http:Server
|
||||||
|
|
||||||
|
construct Latest {
|
||||||
|
release
|
||||||
|
main
|
||||||
|
loader
|
||||||
|
;
|
||||||
|
construct { this | with this ;
|
||||||
|
func read-commit { s | with file ;
|
||||||
|
[ "unzip" "-p" file "commit" ] StreamTypes:cmd:create:read-to-end<32>:to-str
|
||||||
|
}
|
||||||
|
"BaseBand-release.jar" read-commit this:=release
|
||||||
|
"BaseBand-main.jar" read-commit this:=main
|
||||||
|
"BaseBand-Loader.jar" read-commit this:=loader
|
||||||
|
this properties props-to-json
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
construct Object404 {
|
||||||
|
error
|
||||||
|
;
|
||||||
|
construct { this | with this ;
|
||||||
|
"Endpoint not found" this:=error
|
||||||
|
this properties props-to-json
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func props-to-json { | with props ;
|
||||||
|
"{"
|
||||||
|
props
|
||||||
|
:iter
|
||||||
|
:filter<{ b | :to-stack pop with key ; key ":" eq not key ";" eq not and }>
|
||||||
|
:map<{ s |
|
||||||
|
:to-stack with key value ;
|
||||||
|
"\""
|
||||||
|
key :replace<"\\" "\\\\">:replace<"\"" "\\\""> concat
|
||||||
|
"\": \"" concat
|
||||||
|
value _str :replace<"\\" "\\\\">:replace<"\"" "\\\""> concat
|
||||||
|
"\"" concat
|
||||||
|
}>
|
||||||
|
:join<", "> concat
|
||||||
|
"}" concat
|
||||||
|
}
|
||||||
|
|
||||||
|
func main { exitcode | with args ;
|
||||||
|
def server Server:new<"::0" 40002> =server
|
||||||
|
while { 1 } {
|
||||||
|
server:accept &handle-client fork;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handle-client { | with client ;
|
||||||
|
client:read;
|
||||||
|
"index.html" "/" client:serve-html-cached;
|
||||||
|
|
||||||
|
"BaseBand-release.jar" "/download/client/release" client:serve-file-cached;<"application/octet-stream">
|
||||||
|
"BaseBand-main.jar" "/download/client/main" client:serve-file-cached;<"application/octet-stream">
|
||||||
|
"BaseBand-Loader.jar" "/download/loader" client:serve-file-cached;<"application/octet-stream">
|
||||||
|
|
||||||
|
"/latest" client:path eq if {
|
||||||
|
Latest:new client:write-ok:write-content-type<"application/json">:write-str-body:finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
client:wrote-body not if {
|
||||||
|
Object404:new client:write-head<404 "Not Found">:write-content-type<"application/json">:write-str-body:finish;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue