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

Karolis Stulgys

06/10/2022, 11:39 AM
👋 how do I add
/api
prefix for all of my endpoints? I know there is a way, don't remember how
a

Arpad

06/10/2022, 11:57 AM
I think something like this:
Copy code
new Api(stack, "Api", {
  customDomain: {
    domainName: "<http://api.domain.com|api.domain.com>",
    hostedZone: "<http://domain.com|domain.com>",
    path: "v1",
  },
  routes: {
    "GET /notes": "src/list.main",
  },
});
https://docs.serverless-stack.com/constructs/Api#using-the-full-config
f

Frank

06/10/2022, 1:34 PM
Just to add that if you are not using a custom domain, u’d have to prefix each route
Copy code
routes: {
    "GET /api/notes": "src/list.main",
    "GET /api/notes/{id}": "src/get.main",
  },
k

Klaus

06/10/2022, 1:51 PM
@Karolis Stulgys I think Frank's way is the one to use, if you like to e.g. avoid CORS by putting the API with special
/api/
path into the same domain as the UI
3 Views