-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.w
48 lines (41 loc) · 1.16 KB
/
main.w
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
bring cloud;
bring util;
bring http;
let website = new cloud.Website(
path: "./static",
);
let api = new cloud.Api();
website.addJson("config.json", { api: api.url });
let counter = new cloud.Counter() as "website-counter";
let corsHandler = inflight(req) => {
return {
headers: {
"Access-Control-Allow-Headers" => "*",
"Access-Control-Allow-Origin" => "*",
"Access-Control-Allow-Methods" => "OPTIONS,POST",
},
status: 204
};
};
api.options("/hello-static", corsHandler);
api.post("/hello-static", inflight (request) => {
return {
status: 200,
headers: {
"Content-Type" => "text/html",
"Access-Control-Allow-Origin" => "*",
},
body: "<div id=\"hello\" class=\"mt-4\">Hello ${counter.inc()}</div>",
};
});
let invokeAndAssert = inflight(response: http.Response, expected: str) => {
log("response: ${response.status} ");
assert(response.status == 200);
assert(response.body?.contains(expected) == true);
};
test "renders the index page" {
invokeAndAssert(http.get(website.url), "Hello, Wing");
}
test "api returns the correct response" {
invokeAndAssert(http.post("${api.url}/hello-static"), "Hello 0");
}