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

Trey Overton

05/19/2022, 7:11 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?
t

thdxr

05/19/2022, 7:35 PM
this likely isn't related to sst and more to how you're packaging and importing your library
we do support class stacks
bundling "extra assets" in a library is complicated
I would really avoid trying to do this unless it's creating a lot of value for you
t

Trey Overton

05/19/2022, 7:36 PM
The question about class vs functional is actually separate from this question.
t

thdxr

05/19/2022, 7:37 PM
oh ok, for what you want to do you need to define paths like this
Copy code
url.fileURLToPath(import.meta.url);
to get the location of your file
then specify the files it's looking for relatively from there
t

Trey Overton

05/19/2022, 7:39 PM
We build a lot of apps. We have stacks that are identical except for some configuration that is passed in. So we have a package where we have standardized stacks that can then be shared across multiple apps, upgraded everywhere when we improve them. We were doing this before with Serverless Framework and I've been trying to replicate the feature set with SST.
@thdxr you are saying I would replace the string value in the handler property here?
Copy code
props.api.addRoutes(this, {
            ['GET /'.concat(id)]: {
                function: {
                    environment: this.env,
                    permissions: [props.table],
                    handler: 'node_modules/@heatherstoneio/mojo/src/sst/lambdas/placeholder.placeholder'
                }
            }
        });
with the constructed value from the functional call above?
Ah, I see, these are NodeJS functions for working with packages so you don't have to be explicit (as in my sample code above)?
t

thdxr

05/19/2022, 7:44 PM
yeah I don't know exactly how your code needs to be structured but play with specifying it relative from the current file by using that
3 Views