Skip to content

Commit

Permalink
fix(sdk): website has no url protocol on tf-aws (#3757)
Browse files Browse the repository at this point in the history
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)*.
  • Loading branch information
tsuf239 authored Aug 20, 2023
1 parent ab723fa commit 977fa9e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 43 deletions.
13 changes: 2 additions & 11 deletions examples/tests/sdk_tests/website/two_websites.w
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ let w2 = new cloud.Website(path: "./website") as "website-2";


test "deploying two websites" {
let var url1 = w1.url;
if (!url1.startsWith("http")) {
url1 = "http://" + url1;
}
let var url2 = w2.url;
if (!url2.startsWith("http")) {
url2 = "http://" + url2;
}

assert(http.get(url1).ok);
assert(http.get(url2).ok);
assert(http.get(w1.url).ok);
assert(http.get(w2.url).ok);
}
11 changes: 3 additions & 8 deletions examples/tests/sdk_tests/website/website.w
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ assert(w.path.endsWith("sdk_tests/website/website") || w.path.endsWith("sdk_test


test "access files on the website" {
let var url = w.url;
if (!url.startsWith("http")) {
url = "http://" + url;
}

assert(http.get(url).body == indexFile);
assert(http.get(url + "/inner-folder/other.html").body == otherFile);
assert(http.get(url + "/config.json").body == Json.stringify(config));
assert(http.get(w.url).body == indexFile);
assert(http.get(w.url + "/inner-folder/other.html").body == otherFile);
assert(http.get(w.url + "/config.json").body == Json.stringify(config));
}
2 changes: 1 addition & 1 deletion libs/wingsdk/src/target-tf-aws/website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class Website extends cloud.Website {
policy: allowDistributionReadOnly.json,
});

this._url = distribution.domainName;
this._url = `https://${distribution.domainName}`;
}

public get url(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,8 @@ module.exports = function({ $http_Util, $w1_url, $w2_url }) {
return $obj;
}
async handle() {
let url1 = $w1_url;
if ((!url1.startsWith("http"))) {
url1 = ("http://" + url1);
}
let url2 = $w2_url;
if ((!url2.startsWith("http"))) {
url2 = ("http://" + url2);
}
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(url1).ok")})((await $http_Util.get(url1)).ok)};
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(url2).ok")})((await $http_Util.get(url2)).ok)};
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(w1.url).ok")})((await $http_Util.get($w1_url)).ok)};
{((cond) => {if (!cond) throw new Error("assertion failed: http.get(w2.url).ok")})((await $http_Util.get($w2_url)).ok)};
}
}
return $Closure1;
Expand Down Expand Up @@ -304,8 +296,8 @@ module.exports = function({ $http_Util, $w1_url, $w2_url }) {
"variables": {
"WING_FUNCTION_NAME": "Handler-c8683851",
"WING_TARGET": "tf-aws",
"WING_TOKEN_TFTOKEN_TOKEN_16": "${jsonencode(aws_cloudfront_distribution.cloudWebsite_Distribution_083B5AF9.domain_name)}",
"WING_TOKEN_TFTOKEN_TOKEN_32": "${jsonencode(aws_cloudfront_distribution.website-2_Distribution_F1FA4680.domain_name)}"
"WING_TOKEN_HTTPS_TFTOKEN_TOKEN_16": "${jsonencode(\"https://${aws_cloudfront_distribution.cloudWebsite_Distribution_083B5AF9.domain_name}\")}",
"WING_TOKEN_HTTPS_TFTOKEN_TOKEN_32": "${jsonencode(\"https://${aws_cloudfront_distribution.website-2_Distribution_F1FA4680.domain_name}\")}"
}
},
"function_name": "Handler-c8683851",
Expand Down Expand Up @@ -583,8 +575,8 @@ class $Root extends $stdlib.std.Resource {
}
_registerBind(host, ops) {
if (ops.includes("handle")) {
$Closure1._registerBindObject(w1.url, host, []);
$Closure1._registerBindObject(w2.url, host, []);
$Closure1._registerBindObject(w1.url, host, ["ok"]);
$Closure1._registerBindObject(w2.url, host, ["ok"]);
}
super._registerBind(host, ops);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ module.exports = function({ $config, $http_Util, $indexFile, $otherFile, $std_Js
return $obj;
}
async handle() {
let url = $w_url;
if ((!url.startsWith("http"))) {
url = ("http://" + url);
}
{((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)))};
{((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)))};
{((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]))))};
{((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)))};
{((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)))};
{((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]))))};
}
}
return $Closure1;
Expand Down Expand Up @@ -217,7 +213,7 @@ module.exports = function({ }) {
"variables": {
"WING_FUNCTION_NAME": "Handler-c867c4e0",
"WING_TARGET": "tf-aws",
"WING_TOKEN_TFTOKEN_TOKEN_16": "${jsonencode(aws_cloudfront_distribution.cloudWebsite_Distribution_083B5AF9.domain_name)}"
"WING_TOKEN_HTTPS_TFTOKEN_TOKEN_16": "${jsonencode(\"https://${aws_cloudfront_distribution.cloudWebsite_Distribution_083B5AF9.domain_name}\")}"
}
},
"function_name": "Handler-c867c4e0",
Expand Down Expand Up @@ -449,7 +445,7 @@ class $Root extends $stdlib.std.Resource {
$Closure1._registerBindObject(config, host, []);
$Closure1._registerBindObject(indexFile, host, []);
$Closure1._registerBindObject(otherFile, host, []);
$Closure1._registerBindObject(w.url, host, []);
$Closure1._registerBindObject(w.url, host, ["body"]);
}
super._registerBind(host, ops);
}
Expand Down

0 comments on commit 977fa9e

Please sign in to comment.