Are there any examples of multiple stacks in one r...
# help
j
Are there any examples of multiple stacks in one repo?
a
Yes.
Check the examples folder in SST repo.
j
I've been looking in it, but haven't found any
a
There is a typescript example I think.
j
that one only has one stack in it
a
Well yeah.
j
unless i'm missing something
a
But it’s because @thdxr is lazy.
You can add more.
What are you looking for?
I mean, is the exact same config, just add 1 file, haha.
t
haha yeah I was just clicking through them and idk if we have a multi stack example.
a
But what’s the difference?
j
Well, I would like to move my databases to one stack and share to other stacks
a
I mean, just
touch stack2.ts
and past the same content.
So you are looking for dependent stacks.
j
yeah
a
There is somebody in the chat who built an example for that.
And it’s what I’ve used.
Let me check if can find it quick.
j
tks
Did you check that?
This uses dependent stacks.
j
looking
j
ok that is what I was thinking but Typescript does not like it
a
What you mean?
Because is not
stack props
.
j
the
sst.StackProps
does not allow for extra props
a
You have to extend it.
j
k
a
You can’t use that, you have to extend.
Copy code
interface YabbleApiStackProps extends StackProps {
This is what I do.
j
gotcha, makes sense
a
Then my constructor is:
Copy code
constructor(scope: App, id: string, props: YabbleApiStackProps) {
😉
t
I actually stopped extending stack props for the 3rd argument
a
👀
What did you do?
t
I don't actually use any fields in there usually so this is how I've been setting up my stacks
Copy code
type Props = {
  auth: Auth["outputs"]
}

constructor(scope: <http://sst.App|sst.App>, props: Props) {
    super(scope, "backend")
then it's just
Copy code
new Backend(app, { auth: auth.outputs })
a
Ah.
You sending all the outputs.
I prefer to make visible what is being shared.
t
Well you can send specific ones too if you want
I specifically only load whats exposed into Auth.outpus
a
In that case I don’t see much difference.
t
Well I'm not extending the StackProps because I don't need it. Saves a tiny bit
a
Yeah makes sense.
What’s the purpose of…. ?
super(scope, “backend”)
t
The base stack we extend at minimum needs the scope + a name. I prefer hardcoding the name inside the stack instead of passing it in externally
j
that helps alot @thdxr, like the setup that way
f
Hey @Jonathan Chapman, here are some sample code on sharing an Api across stacks. You can share a Table in similar manner https://docs.serverless-stack.com/constructs/Api#sharing-an-api-across-stacks
Let me know if you manage to get it to work 😄
j
I got it working, but the problem with those examples is that it's not Typescript friendly
the
StackProps
does not allow extra properties to be added to it
f
Does viewing the TypeScript version of the snippet help?
j
haha
missed that
a
@Jonathan Chapman you are using typescript, you can take advantage of it 🙂.
If StackProps doesn’t allow something, just extend or don’t use it.
j
yeah, i know, little tired today. It's not helping with trying to make decisions
😄