Hey guys, I’m following this example to share an A...
# sst
a
Hey guys, I’m following this example to share an API that I’ve created on a main stack, with other stacks: https://docs.serverless-stack.com/constructs/Api#importing-an-existing-http-api
Copy code
export class AnotherStack extends Stack {
  constructor(scope: App, id: string, props: AnotherStackProps) {
    super(scope, id, props);

    props.api.addRoutes(this, {
      "GET    /notes/{id}": "src/get.main",
      "PUT    /notes/{id}": "src/update.main",
      "DELETE /notes/{id}": "src/delete.main",
    });
  }
}
The thing is my “routes” all need to have the same “base path” like…
Copy code
/myapp/notes
And I don’t want to put..
Copy code
props.api.addRoutes(this, {
      "GET    /myapp/notes/{id}": "src/get.main",
      "PUT    /myapp/notes/{id}": "src/update.main",
      "DELETE /myapp/notes/{id}": "src/delete.main",
    });
Is there a way to define the
path
for only those routes? I know that I can define the
path
when creating the API from scratch with
customDomain
, but not sure how to do on this scenario.
s
I wrote this, maybe it’ll help you?
then you’d do:
Copy code
props.api.addRoutes(this, generateRoutes(this, 'src/path/path2/', { 'GET /x': 'get.main' }))
generateRoutes
supports mixing just a handler string for your route, or an object
a
I see, that makes sense, thank you for sharing. I was about to do something similar (maybe not this nice, haha).
f
Just wanted to chime in here, @Adrián Mouly if I understood the question correctly, all routes in an Api will have the same custom domain
path
You can either create 2 Apis, and configure the custom domain for 1 to map to
/notes
and the other to map to
/myapp/notes
Or, what you have looks good. And @Sam Hulick’s generator def makes it easier.
a
@Frank yeah I’ve tried creating 3 APIs and share the custom domain, like the SST guide, but for that I need to also create 2 authorizers, etc… I was looking to share all that. Actually now that I think maybe I can share the authorizer lambda by parameter.. going to check.