Louis Barclay
10/23/2021, 4:05 PMNextjsSite
work within my sst API, i.e. run by one of my serverless functions? Use case: I want a route on my API which sets up a new Next.js site for a customer when they request it. In other words, I need an sst construct to be run dynamically within my API. Any tips on how to do this would be much appreciated!
Some more explanation:
• My SaaS sets up Cloudfront distributions for its customers
• I have demand from certain customers to create fully-fledged Next.js apps for them, and I'd like to create these using Cloudfront distributions (for cost reasons and because I already create Cloudfront distributions for my customers)
• Seems like NextjsSite
might do a lot of the hard work of setting up a Next.js app at a Cloudfront distribution if I can get my (sst) API to be able to run itthdxr
10/23/2021, 4:08 PMthdxr
10/23/2021, 4:09 PMthdxr
10/23/2021, 4:10 PMLouis Barclay
10/23/2021, 4:15 PMLouis Barclay
10/23/2021, 4:16 PMthdxr
10/23/2021, 4:25 PMexport default async function main(app: <http://sst.App|sst.App>) {
// Load customer data
const sites = await database.getCustomerSites()
for (let site of sites) {
new SiteStack(app, site.id, site.options)
}
}
class SiteStack extends sst.Stack {
constructor(app: <http://sst.App|sst.App>, id: string, options) {
super(app, id)
const site = new NextJsSite(this, "site", {
optionA: "sadasd",
optionB: "sadasd",
...options
})
}
}
thdxr
10/23/2021, 4:27 PMthdxr
10/23/2021, 4:28 PMthdxr
10/23/2021, 4:29 PMsst deploy --stage siteid
export default async function main(app: <http://sst.App|sst.App>) {
// Load customer data
const site = await database.getCustomerSite(app.stage)
new SiteStack(app, site.id, site.options)
}
class SiteStack extends sst.Stack {
constructor(app: <http://sst.App|sst.App>, id: string, options) {
super(app, id)
const site = new NextJsSite(this, "site", {
optionA: "sadasd",
optionB: "sadasd",
...options
})
}
}
Louis Barclay
10/23/2021, 4:42 PMThis will work but if you have a large number of sites you might need to get more clever and optimize (edited)OOI why would this become problematic as the number of sites increases?
thdxr
10/23/2021, 4:47 PMthdxr
10/23/2021, 4:48 PMLouis Barclay
10/23/2021, 5:49 PM