In the previous chapter we purchased a new domain on Route 53. Now let’s use it for our serverless API.

In your lib/ApiStack.js add the following above the defaultAuthorizationType: "AWS_IAM", line.

  scope.stage === "prod" ? "" : undefined,

This tells SST that we want to use the custom domain if we are deploying to the prod stage. We are not setting one for our dev stage, or any other stage.

We could for example, base it on the stage name, api-${scope.stage} So for dev it might be But we’ll leave that as an exercise for you.

We also need to update the outputs of our API stack.

Replace the this.addOutputs call at the bottom of lib/ApiStack.js.

  ApiEndpoint: this.api.customDomainUrl || this.api.url,

Here we are returning the custom domain URL, if we have one. If not, then we return the auto-generated URL.

Deploy the App

We are now going to deploy our app to prod. You can go ahead and stop the local development environments for SST and React.

Run the following from your project root.

$ npx sst deploy --stage prod

This command will take a few minutes as it’ll deploy your app to a completely new environment. Recall that we are deploying to a separate prod environment because we don’t want to affect our users while we are actively developing our app. This ensures that we have a separate local dev environment and a separate prod environment.

At the end of the deploy process you should see something like this.

Stack prod-notes-api
  Status: no changes

This is great! We now have our app deployed to prod and our API has a custom domain.

Next, let’s use our custom domain for our React app as well.