-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.mini
77 lines (68 loc) · 2.01 KB
/
server.mini
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import: onion("web/onion")
import: minijs("fmt/minijs")
import: json("fmt/json")
def connection_status := onion::connection_status
var Onion := onion()
var Root := Onion:root_url
Root:add(""; Request, Response) do
print("Path = ", Request:get_path, "\n")
print("Full Path = ", Request:get_fullpath, "\n")
let File := file("index.xhtml", "r")
Response:set_code(200)
Response:set_header("Content-Type", "application/xhtml+xml")
Response:write(File:rest)
File:close
Response:flush
end
Root:add("minilang.js"; Request, Response) do
print("Path = ", Request:get_path, "\n")
print("Full Path = ", Request:get_fullpath, "\n")
let File := file("minilang.js", "r")
Response:set_code(200)
Response:set_header("Content-Type", "text/javascript")
Response:write(File:rest)
File:close
Response:flush
end
Root:add("test.js"; Request, Response) do
print("Path = ", Request:get_path, "\n")
print("Full Path = ", Request:get_fullpath, "\n")
let File := file("test.js", "r")
Response:set_code(200)
Response:set_header("Content-Type", "text/javascript")
Response:write(File:rest)
File:close
Response:flush
end
let Globals := map(globals()):grow({
"print" is external("print"),
"json" is external("json")
})
let Externals := external::set()
Externals:add("print", print)
print('Globals = {Globals}\n')
Root:add("compile"; Request, Response) do
let Parser := parser()
let Compiler := compiler(global)
let Input := Request:get_post("input")
print("Input = ", Input, "\n")
Parser:input(Input)
do
let Function := Parser:compile(Compiler)
Response:set_code(200)
Response:set_header("Content-Type", "application/json")
Response:write(json::encode(minijs::encode(Function, Externals)))
on Error do
Response:set_code(400)
Response:set_header("Content-Type", "text/plain")
Response:write('{Error:type}\n')
Response:write('{Error:message}\n')
for (Source, Line) in Error:trace do
Response:write('\t{Source}:{Line}\n')
end
end
Response:flush
end
Onion:set_port("9001")
print("Listening on http://localhost:9001\n")
Onion:listen