Hey I just started testing `sst.Api` and one thing...
# sst
p
Hey I just started testing
sst.Api
and one thing that I noticed was different is that I get a notice of the following for each route:
Copy code
Transpiling Lambda code...
No package.json found in services/mobile-api/
No package.json found in services/mobile-api/
Debug session started. Listening for requests...
I do not see this while defining
sst.Function
s. Note: I use a single package.json in my root folder and many services below this, like
./services/a, ./services/b, ./services/c
f
it seems the 
srcPath
 is set to 
services/mobile-api
 for the routes in your Api?
p
Yes, my service is defined there.
f
what was
srcPath
set to when you were defining
sst.Function
?
p
Would it be better to set this per function? I was just experimenting with using
Copy code
defaultFunctionProps: {
        srcPath: `services/${id}/`
      },
For my functions I use the full path only as part of the
handler
attribute
f
Ah yeah.. I think the warnings does no harm.. but let me check with @Jay
p
It's not a problem, just a gotcha. I'll make sure to try setting the path only on the second part of the routes attr
f
As a side note, does defining the full path work in this case? ie. handler:
services/${id}/lambda.main
p
testing now...
Yeah, so it makes sense. First version works and gives warning.
Copy code
this.api = new sst.Api(this, 'Api', {
  domain: '<http://mydomain.com|mydomain.com>',
  defaultFunctionProps: {
    srcPath: `services/${id}/`
  },
  routes: {
    'GET  /mobile-api/ping2': 'handler.ping',
    'GET  /mobile-api/ping3': {
      authorizationType: sst.ApiAuthorizationType.AWS_IAM,
      function: 'handler.securePing'
    }
  }
})
Second version works and gives no warning:
Copy code
this.api = new sst.Api(this, 'Api', {
  domain: '<http://mydomain.com|mydomain.com>',
  routes: {
    'GET  /mobile-api/ping2': `services/${id}/handler.ping`,
    'GET  /mobile-api/ping3': {
      authorizationType: sst.ApiAuthorizationType.AWS_IAM,
      function: `services/${id}/handler.securePing`
    }
  }
})
Setting
srcPath
does more than just common prefix for handlers if I understand correctly
j
If you are using the
bundle
option, the
srcPath
isn't useful.
p
I think the docs are fine, I was just a lazy bugger and didn't read it properly
j
Nah it makes sense, I would've probably tried to remove the common parts of the path out.
Let me add a note to the docs to make it clear that you shouldn't have to set it.