sst / ion

SST v3
https://sst.dev
MIT License
1.97k stars 229 forks source link

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

Open NamesMT opened 5 months ago

NamesMT commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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

bodhihawken commented 4 months ago

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