Is there a way to pass the is there a way to pass ...
# help
d
Is there a way to pass the is there a way to pass the
api.url
to the functions in one pass?
Copy code
this.api = new sst.Api(this, "Api", {
      defaultAuthorizationType: "AWS_IAM",
      defaultFunctionProps: {
        environment: {
          API_URL: this.api.url, // like here
I want to have access to it in a route. I suppose I can do it just by using
addRoutes
?
f
hmm.. interesting
Here are 2 solutions I can think of: 1. about adding a constant
sst.Api.URL
, and use it like this:
Copy code
this.api = new sst.Api(this, "Api", {
      defaultAuthorizationType: "AWS_IAM",
      defaultFunctionProps: {
        environment: {
          API_URL: sst.Api.URL,
And internally inside
Api
construct, this will be
this.api.url
? 2. using a callback
Copy code
this.api = new sst.Api(this, "Api", {
      defaultAuthorizationType: "AWS_IAM",
      defaultFunctionProps: {
        environment: {
          API_URL: (api) => api.url,
@thdxr what do u guys think?
d
I did it with add routes and that seems to work. Its just adding a small bit of mental overhear to my routes. I can try these other solutions out later today and let you know. In my use case I need to provide a response URL to Twilio.
In case someone is looking for a solution to this in the future. This worked for
addRoutes
.
Copy code
// Response routes have API_URL available here
    this.api.addRoutes(this, {
      "POST     /send-message": {
        function: {
          handler: "src/sendMessage.main",
          environment: {
            API_URL: this.api.url,
          },
        },
      },
    });