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

Peter Slattery

04/25/2022, 11:36 AM
Is it possible to add a path to an sst.Api without setting a domain name? Or, if not, to get the domain name that would have been generated automatically? Basically I just want to use the default domain name and append "/v2" on the end, so that all calls to the api look like "<default domain name>/v2/<api route>" For context, I get an error saying I have to supply a domainName if I do this:
Copy code
this.api = new sst.Api(
  this, 
  "api-name", 
  {
    customDomain: {
      path: "v2"
    }
  }
);
h

Hans Song

04/25/2022, 11:15 PM
just don’t specify one 🙂
Copy code
this.api = new sst.Api(
  this,
  "api-name",
  {
    routes: {
      "GET /v2/xyz": ...
    }
  }
)
add the url to the outputs to see it
Copy code
this.addOutputs({
  apiUrl: this.api.url
})
as far as i’m aware there’s no way to set a default path with http api, you could with the v1 rest api
f

Frank

04/27/2022, 4:13 PM
@Peter Slattery The default API Gateway stage name that comes with HTTP API is empty. If you specified a custom stage name (ie.
v2
), you can accomplish what u want. Here’s an example https://docs.serverless-stack.com/constructs/v1/Api#cdkhttpstages
That said, it is not recommended to use a custom stage name. Many of the `sst.Api`’s built-in features (ie. configuring domain, access logs, etc) only works for the default stage name. You’d need to configure them manually if you used a custom stage name.
I’d recommended to prefix all your routes with
/v2
as @Hans Song suggested.
Let me know if that makes sense.