Skip to content

Commit a91e293

Browse files
authored
Merge pull request #365 from jaulz/patch-1
fix: hide stage in URL in REST scenario
2 parents fc3cfc3 + edb1fd5 commit a91e293

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/constructs/aws/ServerSideWebsite.ts

+4
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,17 @@ export class ServerSideWebsite extends AwsConstruct {
128128
? acm.Certificate.fromCertificateArn(this, "Certificate", configuration.certificate)
129129
: undefined;
130130

131+
// Hide the stage in the URL in REST scenario
132+
const originPath = configuration.apiGateway === "rest" ? "/" + (provider.getStage() ?? "") : undefined;
133+
131134
this.distribution = new Distribution(this, "CDN", {
132135
comment: `${provider.stackName} ${id} website CDN`,
133136
defaultBehavior: {
134137
// Origins are where CloudFront fetches content
135138
origin: new HttpOrigin(apiGatewayDomain, {
136139
// API Gateway only supports HTTPS
137140
protocolPolicy: OriginProtocolPolicy.HTTPS_ONLY,
141+
originPath,
138142
}),
139143
// For a backend app we all all methods
140144
allowedMethods: AllowedMethods.ALLOW_ALL,

src/providers/AwsProvider.ts

+9
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ export class AwsProvider implements ProviderInterface {
141141
return this.serverless.service.provider.vpc ?? null;
142142
}
143143

144+
/**
145+
* Returns name of the stage.
146+
*
147+
* @internal
148+
*/
149+
getStage(): string | undefined {
150+
return this.serverless.service.provider.stage;
151+
}
152+
144153
/**
145154
* Resolves the value of a CloudFormation stack output.
146155
*/

test/unit/serverSideWebsite.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ describe("server-side website", () => {
260260
[{ Ref: "ApiGatewayRestApi" }, "execute-api.us-east-1.amazonaws.com"],
261261
],
262262
},
263+
OriginPath: "/dev",
263264
},
264265
],
265266
},

0 commit comments

Comments
 (0)