Skip to content

Commit 977fa9e

Browse files
authored
fix(sdk): website has no url protocol on tf-aws (#3757)
fixes #3529 ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [x] Description explains motivation and solution - [x] Tests added (always) - [x] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
1 parent ab723fa commit 977fa9e

File tree

5 files changed

+17
-43
lines changed

5 files changed

+17
-43
lines changed

examples/tests/sdk_tests/website/two_websites.w

+2-11
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ let w2 = new cloud.Website(path: "./website") as "website-2";
77

88

99
test "deploying two websites" {
10-
let var url1 = w1.url;
11-
if (!url1.startsWith("http")) {
12-
url1 = "http://" + url1;
13-
}
14-
let var url2 = w2.url;
15-
if (!url2.startsWith("http")) {
16-
url2 = "http://" + url2;
17-
}
18-
19-
assert(http.get(url1).ok);
20-
assert(http.get(url2).ok);
10+
assert(http.get(w1.url).ok);
11+
assert(http.get(w2.url).ok);
2112
}

examples/tests/sdk_tests/website/website.w

+3-8
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ assert(w.path.endsWith("sdk_tests/website/website") || w.path.endsWith("sdk_test
1818

1919

2020
test "access files on the website" {
21-
let var url = w.url;
22-
if (!url.startsWith("http")) {
23-
url = "http://" + url;
24-
}
25-
26-
assert(http.get(url).body == indexFile);
27-
assert(http.get(url + "/inner-folder/other.html").body == otherFile);
28-
assert(http.get(url + "/config.json").body == Json.stringify(config));
21+
assert(http.get(w.url).body == indexFile);
22+
assert(http.get(w.url + "/inner-folder/other.html").body == otherFile);
23+
assert(http.get(w.url + "/config.json").body == Json.stringify(config));
2924
}

libs/wingsdk/src/target-tf-aws/website.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class Website extends cloud.Website {
127127
policy: allowDistributionReadOnly.json,
128128
});
129129

130-
this._url = distribution.domainName;
130+
this._url = `https://${distribution.domainName}`;
131131
}
132132

133133
public get url(): string {

tools/hangar/__snapshots__/test_corpus/sdk_tests/website/two_websites.w_compile_tf-aws.md

+6-14
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,8 @@ module.exports = function({ $http_Util, $w1_url, $w2_url }) {
1010
return $obj;
1111
}
1212
async handle() {
13-
let url1 = $w1_url;
14-
if ((!url1.startsWith("http"))) {
15-
url1 = ("http://" + url1);
16-
}
17-
let url2 = $w2_url;
18-
if ((!url2.startsWith("http"))) {
19-
url2 = ("http://" + url2);
20-
}
21-
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(url1).ok")})((await $http_Util.get(url1)).ok)};
22-
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(url2).ok")})((await $http_Util.get(url2)).ok)};
13+
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(w1.url).ok")})((await $http_Util.get($w1_url)).ok)};
14+
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(w2.url).ok")})((await $http_Util.get($w2_url)).ok)};
2315
}
2416
}
2517
return $Closure1;
@@ -304,8 +296,8 @@ module.exports = function({ $http_Util, $w1_url, $w2_url }) {
304296
"variables": {
305297
"WING_FUNCTION_NAME": "Handler-c8683851",
306298
"WING_TARGET": "tf-aws",
307-
"WING_TOKEN_TFTOKEN_TOKEN_16": "${jsonencode(aws_cloudfront_distribution.cloudWebsite_Distribution_083B5AF9.domain_name)}",
308-
"WING_TOKEN_TFTOKEN_TOKEN_32": "${jsonencode(aws_cloudfront_distribution.website-2_Distribution_F1FA4680.domain_name)}"
299+
"WING_TOKEN_HTTPS_TFTOKEN_TOKEN_16": "${jsonencode(\"https://${aws_cloudfront_distribution.cloudWebsite_Distribution_083B5AF9.domain_name}\")}",
300+
"WING_TOKEN_HTTPS_TFTOKEN_TOKEN_32": "${jsonencode(\"https://${aws_cloudfront_distribution.website-2_Distribution_F1FA4680.domain_name}\")}"
309301
}
310302
},
311303
"function_name": "Handler-c8683851",
@@ -583,8 +575,8 @@ class $Root extends $stdlib.std.Resource {
583575
}
584576
_registerBind(host, ops) {
585577
if (ops.includes("handle")) {
586-
$Closure1._registerBindObject(w1.url, host, []);
587-
$Closure1._registerBindObject(w2.url, host, []);
578+
$Closure1._registerBindObject(w1.url, host, ["ok"]);
579+
$Closure1._registerBindObject(w2.url, host, ["ok"]);
588580
}
589581
super._registerBind(host, ops);
590582
}

tools/hangar/__snapshots__/test_corpus/sdk_tests/website/website.w_compile_tf-aws.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ module.exports = function({ $config, $http_Util, $indexFile, $otherFile, $std_Js
1010
return $obj;
1111
}
1212
async handle() {
13-
let url = $w_url;
14-
if ((!url.startsWith("http"))) {
15-
url = ("http://" + url);
16-
}
17-
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(url).body == indexFile")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((await $http_Util.get(url)).body,$indexFile)))};
18-
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(url + \"/inner-folder/other.html\").body == otherFile")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((await $http_Util.get((url + "/inner-folder/other.html"))).body,$otherFile)))};
19-
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(url + \"/config.json\").body == Json.stringify(config)")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((await $http_Util.get((url + "/config.json"))).body,((args) => { return JSON.stringify(args[0], null, args[1]) })([$config]))))};
13+
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(w.url).body == indexFile")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((await $http_Util.get($w_url)).body,$indexFile)))};
14+
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(w.url + \"/inner-folder/other.html\").body == otherFile")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((await $http_Util.get(($w_url + "/inner-folder/other.html"))).body,$otherFile)))};
15+
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(w.url + \"/config.json\").body == Json.stringify(config)")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((await $http_Util.get(($w_url + "/config.json"))).body,((args) => { return JSON.stringify(args[0], null, args[1]) })([$config]))))};
2016
}
2117
}
2218
return $Closure1;
@@ -217,7 +213,7 @@ module.exports = function({ }) {
217213
"variables": {
218214
"WING_FUNCTION_NAME": "Handler-c867c4e0",
219215
"WING_TARGET": "tf-aws",
220-
"WING_TOKEN_TFTOKEN_TOKEN_16": "${jsonencode(aws_cloudfront_distribution.cloudWebsite_Distribution_083B5AF9.domain_name)}"
216+
"WING_TOKEN_HTTPS_TFTOKEN_TOKEN_16": "${jsonencode(\"https://${aws_cloudfront_distribution.cloudWebsite_Distribution_083B5AF9.domain_name}\")}"
221217
}
222218
},
223219
"function_name": "Handler-c867c4e0",
@@ -449,7 +445,7 @@ class $Root extends $stdlib.std.Resource {
449445
$Closure1._registerBindObject(config, host, []);
450446
$Closure1._registerBindObject(indexFile, host, []);
451447
$Closure1._registerBindObject(otherFile, host, []);
452-
$Closure1._registerBindObject(w.url, host, []);
448+
$Closure1._registerBindObject(w.url, host, ["body"]);
453449
}
454450
super._registerBind(host, ops);
455451
}

0 commit comments

Comments
 (0)