Is it possible to add a path to an sst.Api without...
# help
p
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
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
@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.