Skip to content

Commit

Permalink
Service: fix "no public ports are exposed"
Browse files Browse the repository at this point in the history
closes #795
  • Loading branch information
fwang committed Aug 28, 2024
1 parent b16b138 commit 3310fc1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 0 additions & 1 deletion examples/aws-cluster/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const upload = multer({ storage: multer.memoryStorage() });
console.log(process.env);
console.log(await client());
app.get("/", async (req, res) => {
console.log(c);
res.send("Hello World!");
});

Expand Down
8 changes: 8 additions & 0 deletions examples/aws-cluster/sst-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
import "sst"
declare module "sst" {
export interface Resource {
"MyBucket": {
"name": string
"type": "sst.aws.Bucket"
}
"MyService": {
"type": "sst.aws.Service"
"url": string
}
}
}
export {}
2 changes: 1 addition & 1 deletion examples/aws-cluster/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default $config({
public: true,
});

const vpc = new sst.aws.Vpc("MyVpc");
const vpc = new sst.aws.Vpc("MyVpc", { nat: "managed" });

const cluster = new sst.aws.Cluster("MyCluster", { vpc });

Expand Down
13 changes: 9 additions & 4 deletions platform/src/components/aws/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,15 @@ export class Service extends Component implements Link.Linkable {
* Otherwise, it's the autogenerated load balancer URL.
*/
public get url() {
if (!this.loadBalancer)
throw new VisibleError("No public ports are exposed.");
const errorMessage =
"Cannot access the URL because no public ports are exposed.";
if ($dev) {
if (!this.devUrl) throw new VisibleError(errorMessage);
return this.devUrl;
}

return all([this._url, this.devUrl]).apply(([_url, dev]) => (_url ?? dev)!);
if (!this._url) throw new VisibleError(errorMessage);
return this._url;
}

/**
Expand Down Expand Up @@ -845,7 +850,7 @@ export class Service extends Component implements Link.Linkable {
/** @internal */
public getSSTLink() {
return {
properties: { url: this.loadBalancer ? this.url : undefined },
properties: { url: $dev ? this.devUrl : this._url },
};
}
}
Expand Down

0 comments on commit 3310fc1

Please sign in to comment.