ion icon indicating copy to clipboard operation
ion copied to clipboard

feat(aws/static-site): support `routes` arg

Open NamesMT opened this issue 1 year ago • 3 comments

Refactored to use Router under-the-hood :D, tested locally with working dev, HMR, deploy. Resolves #311

Tested used without routes arg. (like current) Tested with routes from APIGatewayV2, Function

NamesMT avatar Apr 27 '24 09:04 NamesMT

Example snippet of the routes usage:

const backend = new sst.aws.Function('Backend', {
  url: true,
  handler: 'apps/backend/src/index.handler',
})

const staticSiteDistribution = new sst.aws.StaticSite('StaticFullstack', {
  build: {
    command: 'pnpm run build --filter="frontend"',
    output: 'apps/frontend/.output/public',
  },
  routes: {
    '/api/*': backend.url,
  },
})

This deploys my starter-fullstack template to Cloudfront, with the static frontend and Hono backend served on the same domain, with working Live development access from Cloudfront's url.

NamesMT avatar Apr 27 '24 09:04 NamesMT

Note: this update if merged as-is will remove and re-create the distribution for existing deploys.

NamesMT avatar Apr 30 '24 02:04 NamesMT

Love it when someone already has a PR for something i wanted to add. +1

bodhihawken avatar Jun 07 '24 01:06 bodhihawken

@NamesMT refactoring to use Router will cause the distribution to be removed and recreated.

That said, we have plans to attach a site to a router, and you can add additional routes.

But for now, we are moving sst/ion -> sst/sst and unfortunately this is going to be a messy process because of github's limitations

i'm going to close this PR for now and it can be re-opened in the new sst/sst repo that will be ready in the next few days if still relevant

fwang avatar Oct 16 '24 13:10 fwang