https://serverless-stack.com/ logo
#help
Title
# help
k

Karolis Stulgys

06/13/2022, 2:37 PM
👋 can I have my api
customDomain
something like api-hello.great.world.com ? let's say I own world.com domain from aws. I try something similar but when it's deployed the customDomain is still not what I named it
a

Adrian Schweizer

06/13/2022, 4:09 PM
i faintly remember someone who had a similar problem
could it be that the construct just treats everything after the first dot as the domain
maybe show your setup and what it makes of it
i think this was the thread i remembered, its probably not exactly like your issue https://serverless-stack.slack.com/archives/C01JG3B20RY/p1650744821876789
f

Frank

06/13/2022, 10:55 PM
Thanks @Adrian Schweizer!
Yeah this should work
Copy code
customDomain: {
  domainName: "<http://api-hello.great.world.com|api-hello.great.world.com>",
  hostedZone: "<http://world.com|world.com>",
}
k

Karolis Stulgys

06/14/2022, 7:52 AM
Hmm, weird in my api stack I have :
Copy code
customDomain: getCustomDomain(app.stage as "prod" | "dev"),
where `getCustomDomain`: (it's an example)
Copy code
const getCustomDomain = (stage: "prod" | "dev") => {
  return {
    domainName: `${stage}-<http://api.great.world.com|api.great.world.com>`,
    hostedZone: "<http://world.com|world.com>",
  };
};
in seed I have
dev
environment where my backend and frontend is deployed but my frontend still calls random generated api domain ;/
I think I figured that out i should pass
_getCustomDomain_(_stack.stage as_ "prod"
|
"dev")
instead of app.stage. @Frank what's the difference with
stack.stage
and
app.stage
?
a

Adrian Schweizer

06/17/2022, 1:06 PM
Do you deploy single stacks?
I think if you start or deploy with --stage dev, app.stage should be set correctly
Copy code
npx sst start --stage dev
if you use the functional construct, you'll probably have to add app to the parameter destructuring, or it will be null, but since you're using Typescript, it should warn you about that
k

Karolis Stulgys

06/18/2022, 9:36 AM
@Frank just FYI this does not work
Copy code
customDomain: {
  domainName: "<http://api-hello.great.world.com|api-hello.great.world.com>",
  hostedZone: "<http://world.com|world.com>",
}
it does not pass the regex validation. That's what the error says
Copy code
Status: failed
  Error: 1 validation error detected: Value '<https://hello-api.world.hello.com>' at 'domainName' failed to satisfy constraint: Member must satisfy regular expression pattern: ^(\*\.)?(((?!-)[A-Za-z0-9-]{0,62}[A-Za-z0-9])\.)+((?!-)[A-Za-z0-9-]{1,62}[A-Za-z0-9])$ (Service: AWSCertificateManager; Status Code: 400; Error Code: ValidationException; Request ID: e8516c2a-fade-494c-b163-6af0ed29bb92; Proxy: null)
Copy code
'<https://hello-api.world.hello.com>' is just an example but my domain naming is very similar
a

Adrian Schweizer

06/18/2022, 10:12 AM
Are you sure you are defining it without the https:// ? Because according to regex101.com, it does match without it
k

Karolis Stulgys

06/18/2022, 11:08 AM
@Adrian Schweizer wow you actually right. I had https:// in the front.
a

Adrian Schweizer

06/18/2022, 11:10 AM
yeah, i had that problem too, previously
maybe the regex should be set up so that it allows an optional http(s):// prefix
it does say domainName, though, and not URL, so I guess it's correct currently
4 Views