Greg Martin
01/06/2022, 8:17 PM<https://serverless-stack.com/chapters/custom-domains-in-serverless-apis.html>
I am having trouble doing...
api-${scope.stage}.<http://my-serverless-app.com|my-serverless-app.com>
instead of doing this...
customDomain:
scope.stage === "prod" ? "<http://api.my-serverless-app.com|api.my-serverless-app.com>" : undefined,
Just not sure of the syntax, but I do like the idea of basing it on the stage name.Dan Van Brunt
01/06/2022, 8:27 PMcustomDomain: `api-${scope.stage}.<http://my-serverless-app.com|my-serverless-app.com>`
need to add the backticksGreg Martin
01/06/2022, 8:28 PM[Error at /dev-rodeo-sst-api/Api] Found zones: [] for dns:<http://my-serverless-app.com|my-serverless-app.com>, privateZone:undefined, vpcId:undefined, but wanted exactly 1 zone
Greg Martin
01/06/2022, 8:29 PMDan Van Brunt
01/06/2022, 8:29 PM<http://my-serverless-app.com|my-serverless-app.com>
and missing the whole first bit.Greg Martin
01/06/2022, 8:29 PMGreg Martin
01/06/2022, 10:06 PMnpx sst deploy --stage dev
Greg Martin
01/06/2022, 10:06 PMnpx start
Greg Martin
01/06/2022, 10:06 PMGreg Martin
01/06/2022, 10:06 PMDaniel Gato
01/07/2022, 6:06 AMthis.api = new sst.Api(this, 'Api', {
customDomain: {
hostedZone: '<http://mydomainname.io|mydomainname.io>',
domainName:
scope.stage === 'prod'
? '<http://api.mydomainname.io|api.mydomainname.io>'
: `${scope.stage}.<http://api.mydomainname.io|api.mydomainname.io>`,
},
...
frontend stack
const site = new sst.ReactStaticSite(this, 'ReactSite', {
customDomain: {
hostedZone: '<http://mydomainname.io|mydomainname.io>',
domainName:
scope.stage === 'prod'
? '<http://app.mydomainname.io|app.mydomainname.io>'
: `${scope.stage}.<http://app.mydomainname.io|app.mydomainname.io>`,
},
In our case we have:
production:
• api.mydomainname.io for the API
• app.mydomainname.io for the frontend
dev:
• dev.api.mydomainname.io for the API
• dev.app.mydomainname.io for the frontend
other-stage:
• other-stage.api.mydomainname.io for the API
• other-stage.app.mydomainname.io for the frontend
Side note: At first, npx sst start
would tell us it was not able to deploy because there was precedence in the deleting order, but once we did a npx sst deploy --stage our-default-local-stage
(where our-default-local-stage
is the one we use with npx sst start
) everything worked out.