Skip to content

Commit

Permalink
Merge pull request #365 from jaulz/patch-1
Browse files Browse the repository at this point in the history
fix: hide stage in URL in REST scenario
  • Loading branch information
mnapoli authored Nov 7, 2023
2 parents fc3cfc3 + edb1fd5 commit a91e293
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/constructs/aws/ServerSideWebsite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,17 @@ export class ServerSideWebsite extends AwsConstruct {
? acm.Certificate.fromCertificateArn(this, "Certificate", configuration.certificate)
: undefined;

// Hide the stage in the URL in REST scenario
const originPath = configuration.apiGateway === "rest" ? "/" + (provider.getStage() ?? "") : undefined;

this.distribution = new Distribution(this, "CDN", {
comment: `${provider.stackName} ${id} website CDN`,
defaultBehavior: {
// Origins are where CloudFront fetches content
origin: new HttpOrigin(apiGatewayDomain, {
// API Gateway only supports HTTPS
protocolPolicy: OriginProtocolPolicy.HTTPS_ONLY,
originPath,
}),
// For a backend app we all all methods
allowedMethods: AllowedMethods.ALLOW_ALL,
Expand Down
9 changes: 9 additions & 0 deletions src/providers/AwsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ export class AwsProvider implements ProviderInterface {
return this.serverless.service.provider.vpc ?? null;
}

/**
* Returns name of the stage.
*
* @internal
*/
getStage(): string | undefined {
return this.serverless.service.provider.stage;
}

/**
* Resolves the value of a CloudFormation stack output.
*/
Expand Down
1 change: 1 addition & 0 deletions test/unit/serverSideWebsite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ describe("server-side website", () => {
[{ Ref: "ApiGatewayRestApi" }, "execute-api.us-east-1.amazonaws.com"],
],
},
OriginPath: "/dev",
},
],
},
Expand Down

0 comments on commit a91e293

Please sign in to comment.