https://serverless-stack.com/ logo
#sst
Title
# sst
t

Trey Overton

05/19/2022, 2:02 PM
I have a stack defined in a package I import into my actual application. Routes that I define would use handlers that seem to require being specified by file path only. This means that when imported, it wants to go after a file location in the consuming app, not the location in the imported stack's package. Is there a way around this?
So far, my only solution seems to be to set the handler to be a path into node_modules to the src folder included in the package.
t

Tim

05/19/2022, 9:07 PM
I have something similar and ended up doing this in the imported stack
Copy code
const root = this.node.root as <http://sst.App|sst.App>;
const { appPath } = root;
const dirname = path.relative(appPath, __dirname);
where
dirname
has the relative path from the app root to the stack definition inside
node_modules
from there you can add the path to the file with the function handler
t

Trey Overton

05/20/2022, 1:49 PM
@Tim I had re-posted in #help and there was a similar suggestion, but using some NodeJS functions:
Copy code
url.fileURLToPath(import.meta.url);
Perhaps this might be an alternative to your version, except yours already works, so is amazing.
2 Views