How can I use customDomains for the Api Construct ...
# help
a
How can I use customDomains for the Api Construct conditionally, such as on the basis of
stageName
?
f
Copy code
new Api(this, "Api", {
  customDomain: {
    domainName: scope.stage === "prod" ? "<http://api.domain.com|api.domain.com>" : `${scope.stage}.<http://api.domain.com|api.domain.com>",
    hostedZone: "<http://domain.com|domain.com>",
  },
  routes: {
    "GET /notes": "src/list.main",
  },
});
Does something like this work for you?
a
how can I not set a custom domain for a specific stage?
f
Give this a try:
Copy code
new Api(this, "Api", {
  customDomain: scope.stage === "prod" ? "<http://api.domain.com|api.domain.com>" : undefined,
  routes: {
    "GET /notes": "src/list.main",
  },
});
a
I'm using an object for customDomain, I'm setting the path as well, will that be unset by undefined?
f
Yup setting it to
undefined
will disable customDomain
a
Okay, that's great, thank you.