-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileserver.oak
More file actions
34 lines (26 loc) · 725 Bytes
/
fileserver.oak
File metadata and controls
34 lines (26 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// basic file server using libhttp
std := import('std')
fmt := import('fmt')
http := import('http')
Port := 9990
server := http.Server()
with server.route('/hello/:name') fn(params) fn(req, end) if req.method {
'GET' -> end({
status: 200
body: fmt.format('Hello, {{ 0 }}!', std.default(params.name, 'World'))
})
_ -> end(http.MethodNotAllowed)
}
with server.route('/*staticPath') fn(params) {
http.handleStatic('./' + params.staticPath)
}
with server.route('/') fn(params) fn(req, end) if req.method {
'GET' -> end({
status: 200
body: 'Welcome to Oak!'
})
_ -> end(http.MethodNotAllowed)
}
// start server
server.startThreaded(Port)
fmt.printf('Static server (threaded) running at port {{ 0 }}', Port)