From 2112c7198362f5f2281bed56b6e1213935697d88 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 10:37:43 +0200 Subject: [PATCH 01/21] wip --- main.w | 9 +-------- on_deploy.main.w | 9 --------- website/index.html | 4 ++++ 3 files changed, 5 insertions(+), 17 deletions(-) delete mode 100644 on_deploy.main.w create mode 100644 website/index.html diff --git a/main.w b/main.w index 1132a80..8731a43 100644 --- a/main.w +++ b/main.w @@ -1,10 +1,3 @@ bring cloud; -let secret = new cloud.Secret( - name: "MY_SECRET", -); - -new cloud.Function(inflight () => { - return secret.value(); -}); - +new cloud.Website(path: "./website"); diff --git a/on_deploy.main.w b/on_deploy.main.w deleted file mode 100644 index 580464e..0000000 --- a/on_deploy.main.w +++ /dev/null @@ -1,9 +0,0 @@ -bring cloud; - -let secret = new cloud.Secret( - name: "MY_SECRET", -); - -new cloud.OnDeploy(inflight () => { - throw "SECRET VALUE: '{secret.value()}'"; -}); diff --git a/website/index.html b/website/index.html new file mode 100644 index 0000000..5da6e06 --- /dev/null +++ b/website/index.html @@ -0,0 +1,4 @@ +
+

Website

+

Website content goes here.

+
From 8b4ae491de3258f8d80bed6f30e26640422408e7 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 10:42:24 +0200 Subject: [PATCH 02/21] wip --- main.w | 58 +++++++++++++++++++++++++++++++++++++++++++++- website/index.html | 47 +++++++++++++++++++++++++++++++++---- 2 files changed, 100 insertions(+), 5 deletions(-) diff --git a/main.w b/main.w index 8731a43..4a5093e 100644 --- a/main.w +++ b/main.w @@ -1,3 +1,59 @@ bring cloud; +bring util; +bring http; +bring expect; -new cloud.Website(path: "./website"); +let website = new cloud.Website( + path: "./website", +); + +let api = new cloud.Api({ + cors: true, + corsOptions: { + allowHeaders: ["*"], + allowMethods: [http.HttpMethod.POST], + }, +}); +website.addJson("config.json", { api: api.url }); + +let counter = new cloud.Counter() as "website-counter"; + +api.post("/hello-static", inflight (request) => { + return { + status: 200, + headers: { + "Content-Type" => "text/html", + "Access-Control-Allow-Origin" => "*", + }, + body: "
Hello {counter.inc()}
", + }; +}); + +let invokeAndAssert = inflight(response: http.Response, expected: str) => { + log("response: {response.status} "); + expect.equal(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"); +} + +test "api handles cors" { + let response = http.fetch("{api.url}/hello-static", { + method: http.HttpMethod.OPTIONS, + headers: { + "Origin" => "https://example.com", + "hx-target" => "hello", + }, + }); + expect.equal(response.status, 204); + log("headers: {Json.stringify(response.headers)}"); + expect.equal(response.headers.get("access-control-allow-headers"), "*"); + expect.equal(response.headers.get("access-control-allow-origin"), "*"); + expect.equal(response.headers.get("access-control-allow-methods"), "POST"); +} diff --git a/website/index.html b/website/index.html index 5da6e06..e3c5d28 100644 --- a/website/index.html +++ b/website/index.html @@ -1,4 +1,43 @@ -
-

Website

-

Website content goes here.

-
+ + + + + + Hello Wing + + + + + + + +
+

Hello, Wing

+ +
+
+ + + From 79e99af30ddd8b46ab0759fa4f66d55e627b5834 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 10:45:17 +0200 Subject: [PATCH 03/21] wip --- main.w | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.w b/main.w index 4a5093e..befb748 100644 --- a/main.w +++ b/main.w @@ -11,7 +11,7 @@ let api = new cloud.Api({ cors: true, corsOptions: { allowHeaders: ["*"], - allowMethods: [http.HttpMethod.POST], + allowMethods: [http.HttpMethod.POST, http.HttpMethod.GET], }, }); website.addJson("config.json", { api: api.url }); From 7a7275c863aad5ed8ab1b1206f6ffda2c44ac4b9 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 10:46:00 +0200 Subject: [PATCH 04/21] wip --- main.w | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.w b/main.w index befb748..3a9d169 100644 --- a/main.w +++ b/main.w @@ -30,20 +30,24 @@ api.post("/hello-static", inflight (request) => { }); let invokeAndAssert = inflight(response: http.Response, expected: str) => { + log("api.url: {api.url}"); log("response: {response.status} "); expect.equal(response.status, 200); assert(response.body?.contains(expected) == true); }; test "renders the index page" { + log("api.url: {api.url}"); invokeAndAssert(http.get(website.url), "Hello, Wing"); } test "api returns the correct response" { + log("api.url: {api.url}"); invokeAndAssert(http.post("{api.url}/hello-static"), "Hello 0"); } test "api handles cors" { + log("api.url: {api.url}"); let response = http.fetch("{api.url}/hello-static", { method: http.HttpMethod.OPTIONS, headers: { From 69547b442822defb87f89f579553ff5be13a3948 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 10:47:44 +0200 Subject: [PATCH 05/21] wip --- main.w | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.w b/main.w index 3a9d169..89ae55d 100644 --- a/main.w +++ b/main.w @@ -11,7 +11,8 @@ let api = new cloud.Api({ cors: true, corsOptions: { allowHeaders: ["*"], - allowMethods: [http.HttpMethod.POST, http.HttpMethod.GET], + allowMethods: [http.HttpMethod.POST], + allowOrigin: "*" }, }); website.addJson("config.json", { api: api.url }); From 2f2f842fa43f12050ede2361a08f81a5c203d0f4 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 10:50:32 +0200 Subject: [PATCH 06/21] wip --- main.w | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.w b/main.w index 89ae55d..9b8e5bd 100644 --- a/main.w +++ b/main.w @@ -12,7 +12,6 @@ let api = new cloud.Api({ corsOptions: { allowHeaders: ["*"], allowMethods: [http.HttpMethod.POST], - allowOrigin: "*" }, }); website.addJson("config.json", { api: api.url }); @@ -38,7 +37,7 @@ let invokeAndAssert = inflight(response: http.Response, expected: str) => { }; test "renders the index page" { - log("api.url: {api.url}"); + log("api.url: {website.url}"); invokeAndAssert(http.get(website.url), "Hello, Wing"); } From 8378f443d40752ce8826faba1f6ea686d33455b7 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 10:50:53 +0200 Subject: [PATCH 07/21] wip --- main.w | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.w b/main.w index 9b8e5bd..e5da72d 100644 --- a/main.w +++ b/main.w @@ -16,7 +16,7 @@ let api = new cloud.Api({ }); website.addJson("config.json", { api: api.url }); -let counter = new cloud.Counter() as "website-counter"; +let counter = new cloud.Counter(initial: 0) as "website-counter"; api.post("/hello-static", inflight (request) => { return { From 20db951ee27bd21a19910f05c2af096019c71fff Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 10:52:41 +0200 Subject: [PATCH 08/21] wip --- main.w | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.w b/main.w index e5da72d..a144892 100644 --- a/main.w +++ b/main.w @@ -16,7 +16,7 @@ let api = new cloud.Api({ }); website.addJson("config.json", { api: api.url }); -let counter = new cloud.Counter(initial: 0) as "website-counter"; +let counter = new cloud.Counter(initial: 0) as "website-counter-2"; api.post("/hello-static", inflight (request) => { return { From 8f96b6f9d54d4e15ca14d343689242f1aac2d8df Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 10:55:47 +0200 Subject: [PATCH 09/21] wip --- main.w | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main.w b/main.w index a144892..6cfca31 100644 --- a/main.w +++ b/main.w @@ -38,11 +38,16 @@ let invokeAndAssert = inflight(response: http.Response, expected: str) => { test "renders the index page" { log("api.url: {website.url}"); - invokeAndAssert(http.get(website.url), "Hello, Wing"); + try { + let response = http.get(website.url); + expect.equal(response.status, 200); + assert(response.body?.contains("Hello, Wing") == true); + } catch e { + log("error: {e}"); + } } test "api returns the correct response" { - log("api.url: {api.url}"); invokeAndAssert(http.post("{api.url}/hello-static"), "Hello 0"); } From 4b623ac398efc33b10dd3b9ff08f6f597c5ebc87 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 10:58:47 +0200 Subject: [PATCH 10/21] wip --- main.w | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/main.w b/main.w index 6cfca31..c9bc906 100644 --- a/main.w +++ b/main.w @@ -16,8 +16,6 @@ let api = new cloud.Api({ }); website.addJson("config.json", { api: api.url }); -let counter = new cloud.Counter(initial: 0) as "website-counter-2"; - api.post("/hello-static", inflight (request) => { return { status: 200, @@ -25,44 +23,18 @@ api.post("/hello-static", inflight (request) => { "Content-Type" => "text/html", "Access-Control-Allow-Origin" => "*", }, - body: "
Hello {counter.inc()}
", + body: "
Hello from the API!
", }; }); -let invokeAndAssert = inflight(response: http.Response, expected: str) => { - log("api.url: {api.url}"); - log("response: {response.status} "); - expect.equal(response.status, 200); - assert(response.body?.contains(expected) == true); -}; - test "renders the index page" { - log("api.url: {website.url}"); + log("website.url: {website.url}"); try { let response = http.get(website.url); expect.equal(response.status, 200); assert(response.body?.contains("Hello, Wing") == true); } catch e { log("error: {e}"); + assert(false); } } - -test "api returns the correct response" { - invokeAndAssert(http.post("{api.url}/hello-static"), "Hello 0"); -} - -test "api handles cors" { - log("api.url: {api.url}"); - let response = http.fetch("{api.url}/hello-static", { - method: http.HttpMethod.OPTIONS, - headers: { - "Origin" => "https://example.com", - "hx-target" => "hello", - }, - }); - expect.equal(response.status, 204); - log("headers: {Json.stringify(response.headers)}"); - expect.equal(response.headers.get("access-control-allow-headers"), "*"); - expect.equal(response.headers.get("access-control-allow-origin"), "*"); - expect.equal(response.headers.get("access-control-allow-methods"), "POST"); -} From 5fd3389cc726cd964436d18bb59fb3ef1871c25e Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 11:07:11 +0200 Subject: [PATCH 11/21] add get --- main.w | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main.w b/main.w index c9bc906..364b675 100644 --- a/main.w +++ b/main.w @@ -16,6 +16,17 @@ let api = new cloud.Api({ }); website.addJson("config.json", { api: api.url }); +api.get("/", inflight (request) => { + return { + status: 200, + headers: { + "Content-Type" => "text/html", + "Access-Control-Allow-Origin" => "*", + }, + body: "
Hello from the API!
", + }; +}); + api.post("/hello-static", inflight (request) => { return { status: 200, From c4e6aa6207b09264d3fb46b6480b9fe92826d316 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 11:10:59 +0200 Subject: [PATCH 12/21] wip --- main.w | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/main.w b/main.w index 364b675..f1843fe 100644 --- a/main.w +++ b/main.w @@ -1,5 +1,4 @@ bring cloud; -bring util; bring http; bring expect; @@ -7,37 +6,6 @@ let website = new cloud.Website( path: "./website", ); -let api = new cloud.Api({ - cors: true, - corsOptions: { - allowHeaders: ["*"], - allowMethods: [http.HttpMethod.POST], - }, -}); -website.addJson("config.json", { api: api.url }); - -api.get("/", inflight (request) => { - return { - status: 200, - headers: { - "Content-Type" => "text/html", - "Access-Control-Allow-Origin" => "*", - }, - body: "
Hello from the API!
", - }; -}); - -api.post("/hello-static", inflight (request) => { - return { - status: 200, - headers: { - "Content-Type" => "text/html", - "Access-Control-Allow-Origin" => "*", - }, - body: "
Hello from the API!
", - }; -}); - test "renders the index page" { log("website.url: {website.url}"); try { From 0701cbfe99e567bd669887921abc9844e6cb63f5 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 11:17:22 +0200 Subject: [PATCH 13/21] wip --- main.w | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/main.w b/main.w index f1843fe..6b656a1 100644 --- a/main.w +++ b/main.w @@ -1,19 +1,45 @@ bring cloud; +bring util; bring http; bring expect; let website = new cloud.Website( - path: "./website", + path: "./static", ); +let api = new cloud.Api({ + cors: true, + corsOptions: { + allowHeaders: ["*"], + allowMethods: [http.HttpMethod.POST], + }, +}); +website.addJson("config.json", { api: api.url }); + + +api.post("/hello-static", inflight (request) => { + return { + status: 200, + headers: { + "Content-Type" => "text/html", + "Access-Control-Allow-Origin" => "*", + }, + body: "
Hello from the server
", + }; +}); + +let invokeAndAssert = inflight(response: http.Response, expected: str) => { + log("response: {response.status} "); + expect.equal(response.status, 200); + assert(response.body?.contains(expected) == true); +}; + test "renders the index page" { log("website.url: {website.url}"); - try { - let response = http.get(website.url); - expect.equal(response.status, 200); - assert(response.body?.contains("Hello, Wing") == true); - } catch e { - log("error: {e}"); - assert(false); - } + invokeAndAssert(http.get(website.url), "Hello, Wing"); +} + +test "api returns the correct response" { + log("api.url: {api.url}"); + invokeAndAssert(http.post("{api.url}/hello-static"), "Hello from the server"); } From f6e5725510508eaca8aa455ae5b00b33656a4217 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 11:31:57 +0200 Subject: [PATCH 14/21] wip --- main.w | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.w b/main.w index 6b656a1..9b3551b 100644 --- a/main.w +++ b/main.w @@ -41,5 +41,10 @@ test "renders the index page" { test "api returns the correct response" { log("api.url: {api.url}"); - invokeAndAssert(http.post("{api.url}/hello-static"), "Hello from the server"); + try { + invokeAndAssert(http.post("{api.url}/hello-static"), "Hello from the server"); + } catch error { + log("error: {error}"); + assert(false); + } } From bb61788c4db8f1e35674bfbed7a162c7e609683b Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 11:47:03 +0200 Subject: [PATCH 15/21] wip --- main.w | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.w b/main.w index 9b3551b..55e0b38 100644 --- a/main.w +++ b/main.w @@ -39,7 +39,17 @@ test "renders the index page" { invokeAndAssert(http.get(website.url), "Hello, Wing"); } -test "api returns the correct response" { +test "1- api returns the correct response" { + log("api.url: {api.url}"); + try { + invokeAndAssert(http.post("{api.url}/hello-static"), "Hello from the server"); + } catch error { + log("error: {error}"); + assert(false); + } +} + +test "2- api returns the correct response" { log("api.url: {api.url}"); try { invokeAndAssert(http.post("{api.url}/hello-static"), "Hello from the server"); From 29817ea8d485dbf970c329cb415bc12070cbd719 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 11:51:19 +0200 Subject: [PATCH 16/21] wip --- main.w | 1 + 1 file changed, 1 insertion(+) diff --git a/main.w b/main.w index 55e0b38..8f36961 100644 --- a/main.w +++ b/main.w @@ -41,6 +41,7 @@ test "renders the index page" { test "1- api returns the correct response" { log("api.url: {api.url}"); + util.sleep(duration.fromMinutes(1)); try { invokeAndAssert(http.post("{api.url}/hello-static"), "Hello from the server"); } catch error { From 440a5b47598a8217c6b8d38810b44ed5af941c46 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 11:52:30 +0200 Subject: [PATCH 17/21] wip --- main.w | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.w b/main.w index 8f36961..e65f6f2 100644 --- a/main.w +++ b/main.w @@ -46,7 +46,7 @@ test "1- api returns the correct response" { invokeAndAssert(http.post("{api.url}/hello-static"), "Hello from the server"); } catch error { log("error: {error}"); - assert(false); + //assert(false); } } @@ -56,6 +56,6 @@ test "2- api returns the correct response" { invokeAndAssert(http.post("{api.url}/hello-static"), "Hello from the server"); } catch error { log("error: {error}"); - assert(false); + //assert(false); } } From b8ae2bf48b03f9665e5f0b16927e019794c01b40 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 11:56:27 +0200 Subject: [PATCH 18/21] wip --- main.w | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.w b/main.w index e65f6f2..b313c32 100644 --- a/main.w +++ b/main.w @@ -41,12 +41,12 @@ test "renders the index page" { test "1- api returns the correct response" { log("api.url: {api.url}"); - util.sleep(duration.fromMinutes(1)); + util.sleep(duration.fromSeconds(10)); try { invokeAndAssert(http.post("{api.url}/hello-static"), "Hello from the server"); } catch error { log("error: {error}"); - //assert(false); + assert(false); } } @@ -56,6 +56,6 @@ test "2- api returns the correct response" { invokeAndAssert(http.post("{api.url}/hello-static"), "Hello from the server"); } catch error { log("error: {error}"); - //assert(false); + assert(false); } } From e8a042c4d75e330393c0967bee46d4ce959e8c42 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 12:12:37 +0200 Subject: [PATCH 19/21] wip --- .env | 1 - main.w | 18 ++++-------------- website/index.html | 21 +-------------------- 3 files changed, 5 insertions(+), 35 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index 3dd9dc7..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -MY_SECRET=value diff --git a/main.w b/main.w index b313c32..a4646ce 100644 --- a/main.w +++ b/main.w @@ -4,7 +4,7 @@ bring http; bring expect; let website = new cloud.Website( - path: "./static", + path: "./website", ); let api = new cloud.Api({ @@ -14,6 +14,7 @@ let api = new cloud.Api({ allowMethods: [http.HttpMethod.POST], }, }); + website.addJson("config.json", { api: api.url }); @@ -29,7 +30,7 @@ api.post("/hello-static", inflight (request) => { }); let invokeAndAssert = inflight(response: http.Response, expected: str) => { - log("response: {response.status} "); + log("response: {Json.stringify(response)} "); expect.equal(response.status, 200); assert(response.body?.contains(expected) == true); }; @@ -39,18 +40,7 @@ test "renders the index page" { invokeAndAssert(http.get(website.url), "Hello, Wing"); } -test "1- api returns the correct response" { - log("api.url: {api.url}"); - util.sleep(duration.fromSeconds(10)); - try { - invokeAndAssert(http.post("{api.url}/hello-static"), "Hello from the server"); - } catch error { - log("error: {error}"); - assert(false); - } -} - -test "2- api returns the correct response" { +test "api returns the correct response" { log("api.url: {api.url}"); try { invokeAndAssert(http.post("{api.url}/hello-static"), "Hello from the server"); diff --git a/website/index.html b/website/index.html index e3c5d28..de5133e 100644 --- a/website/index.html +++ b/website/index.html @@ -17,27 +17,8 @@

Hello, Wing

- +
- From dfa697e6053cafa63af7f7c3ee707ff3fe9de17c Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 12:15:47 +0200 Subject: [PATCH 20/21] wip --- main.w | 47 +++++++---------------------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/main.w b/main.w index a4646ce..ad9a269 100644 --- a/main.w +++ b/main.w @@ -4,48 +4,15 @@ bring http; bring expect; let website = new cloud.Website( - path: "./website", + path: "./websitew", ); -let api = new cloud.Api({ - cors: true, - corsOptions: { - allowHeaders: ["*"], - allowMethods: [http.HttpMethod.POST], - }, -}); - -website.addJson("config.json", { api: api.url }); - - -api.post("/hello-static", inflight (request) => { - return { - status: 200, - headers: { - "Content-Type" => "text/html", - "Access-Control-Allow-Origin" => "*", - }, - body: "
Hello from the server
", - }; -}); - -let invokeAndAssert = inflight(response: http.Response, expected: str) => { - log("response: {Json.stringify(response)} "); - expect.equal(response.status, 200); - assert(response.body?.contains(expected) == true); -}; - test "renders the index page" { log("website.url: {website.url}"); - invokeAndAssert(http.get(website.url), "Hello, Wing"); -} - -test "api returns the correct response" { - log("api.url: {api.url}"); - try { - invokeAndAssert(http.post("{api.url}/hello-static"), "Hello from the server"); - } catch error { - log("error: {error}"); - assert(false); - } + let response = http.get(website.url); + log("response: {Json.stringify(response)} "); + + expect.equal(response.status, 200); + assert(response.body?.contains("Hello, Wing") == true); + } From eebe6acc8f6f51f90b89b9c8cebe0d4db840beb9 Mon Sep 17 00:00:00 2001 From: polamoros Date: Thu, 16 May 2024 12:16:41 +0200 Subject: [PATCH 21/21] wip --- main.w | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.w b/main.w index ad9a269..ecf1b1d 100644 --- a/main.w +++ b/main.w @@ -4,11 +4,12 @@ bring http; bring expect; let website = new cloud.Website( - path: "./websitew", + path: "./website", ); test "renders the index page" { log("website.url: {website.url}"); + let response = http.get(website.url); log("response: {Json.stringify(response)} ");