diff --git a/.changeset/config.json b/.changeset/config.json index 8fd74d86d..68a990d27 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -3,14 +3,7 @@ "changelog": ["@changesets/changelog-github", { "repo": "sst/v2" }], "commit": false, "fixed": [ - [ - "@sst/console", - "create-sst", - "sst", - "astro-sst", - "svelte-kit-sst", - "solid-start-sst" - ] + ["@sst/console", "create-sst", "sst", "svelte-kit-sst", "solid-start-sst"] ], "linked": [], "access": "public", diff --git a/packages/astro-sst/CHANGELOG.md b/packages/astro-sst/CHANGELOG.md deleted file mode 100644 index b0bbc31e3..000000000 --- a/packages/astro-sst/CHANGELOG.md +++ /dev/null @@ -1,899 +0,0 @@ -# astro-sst - -## 2.45.1 - -## 2.45.0 - -## 2.44.3 - -## 2.44.2 - -## 2.44.1 - -## 2.44.0 - -## 2.43.8 - -## 2.43.7 - -## 2.43.6 - -### Patch Changes - -- [`a68ca8416`](https://github.com/sst/sst/commit/a68ca84160bc87460e4fb09a4893640ad11daebf) Thanks [@thdxr](https://github.com/thdxr)! - switch to v2 tag - -## 2.43.5 - -## 2.43.4 - -## 2.43.3 - -## 2.43.2 - -## 2.43.1 - -## 2.43.0 - -## 2.42.0 - -## 2.41.5 - -## 2.41.4 - -## 2.41.3 - -## 2.41.2 - -## 2.41.1 - -## 2.41.0 - -## 2.40.8 - -## 2.40.7 - -## 2.40.6 - -## 2.40.5 - -## 2.40.4 - -## 2.40.3 - -## 2.40.2 - -### Patch Changes - -- [#3591](https://github.com/sst/sst/pull/3591) [`988fb7843`](https://github.com/sst/sst/commit/988fb7843562749a4503e0c730b29a4868eeb984) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - AstroSite: update render call to remove deprecation notice in logs. - -## 2.40.1 - -### Patch Changes - -- [#3647](https://github.com/sst/sst/pull/3647) [`92a8de72a`](https://github.com/sst/sst/commit/92a8de72ac1b793cf016e7cd5471a033548a1e6c) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - Astro: add client address property - -## 2.40.0 - -## 2.39.13 - -## 2.39.12 - -## 2.39.11 - -## 2.39.10 - -## 2.39.9 - -## 2.39.8 - -## 2.39.7 - -## 2.39.6 - -## 2.39.5 - -## 2.39.4 - -## 2.39.3 - -## 2.39.2 - -## 2.39.1 - -## 2.39.0 - -## 2.38.7 - -## 2.38.6 - -## 2.38.5 - -## 2.38.4 - -## 2.38.3 - -## 2.38.2 - -## 2.38.1 - -## 2.38.0 - -## 2.37.2 - -### Patch Changes - -- [#3559](https://github.com/sst/sst/pull/3559) [`4d7d69d4e`](https://github.com/sst/sst/commit/4d7d69d4e8ce1f98ea307d0db49721f4b5d27a90) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - astro-sst: support Starlight - -## 2.37.1 - -### Patch Changes - -- [#3493](https://github.com/sst/sst/pull/3493) [`d5d31fdda`](https://github.com/sst/sst/commit/d5d31fddae14a2948a9b8da4b9894044eeaa6b78) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - AstroSite: add sharp image processing - -- [#3560](https://github.com/sst/sst/pull/3560) [`0229f9892`](https://github.com/sst/sst/commit/0229f9892f984aab31b407128ab381cf1295e153) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - astro-sst: update to Astro v4 - -## 2.37.0 - -## 2.36.8 - -## 2.36.7 - -## 2.36.6 - -## 2.36.5 - -## 2.36.4 - -## 2.36.3 - -## 2.36.2 - -## 2.36.1 - -## 2.36.0 - -## 2.35.1 - -### Patch Changes - -- [#3498](https://github.com/sst/sst/pull/3498) [`97bc385e2`](https://github.com/sst/sst/commit/97bc385e2a56953c8511e034bc91bbd3360663a1) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - AstroSite: fixes bug with config override causing issues with MDX plugin - -## 2.35.0 - -### Patch Changes - -- [`ffa4b0fe9`](https://github.com/sst/sst/commit/ffa4b0fe95e3527ef590f9b8a23e095fdaa227a2) Thanks [@fwang](https://github.com/fwang)! - AstroSite: support server function sourcemap - -## 2.34.7 - -## 2.34.6 - -## 2.34.5 - -## 2.34.4 - -## 2.34.3 - -## 2.34.2 - -## 2.34.1 - -## 2.34.0 - -### Minor Changes - -- [#3458](https://github.com/sst/sst/pull/3458) [`3c12694c9`](https://github.com/sst/sst/commit/3c12694c990ff2ffd64f6736a6ac5546d708ba43) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - AstroSite: infer edge deployment from astro-sst adapter - -### Patch Changes - -- [#3458](https://github.com/sst/sst/pull/3458) [`3c12694c9`](https://github.com/sst/sst/commit/3c12694c990ff2ffd64f6736a6ac5546d708ba43) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - astro-sst: unify regional and edge adapters - -## 2.33.4 - -## 2.33.3 - -## 2.33.2 - -## 2.33.1 - -## 2.33.0 - -## 2.32.3 - -### Patch Changes - -- [#3444](https://github.com/sst/sst/pull/3444) [`ac26313e3`](https://github.com/sst/sst/commit/ac26313e3b86e7d1e3c4887d740679ad292d51aa) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - AstroSite: add static generation support - -## 2.32.2 - -## 2.32.1 - -## 2.32.0 - -## 2.31.0 - -## 2.30.4 - -## 2.30.3 - -## 2.30.2 - -## 2.30.1 - -## 2.30.0 - -### Patch Changes - -- [#3420](https://github.com/sst/sst/pull/3420) [`c8a3509ff`](https://github.com/sst/sst/commit/c8a3509ff51d851170003e94ebd4bdf280e5f8d5) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - AstroSite: Fixed invalid format for set-cookie headers in server response - -## 2.29.2 - -## 2.29.1 - -## 2.29.0 - -## 2.28.6 - -## 2.28.5 - -## 2.28.4 - -## 2.28.3 - -## 2.28.2 - -## 2.28.1 - -### Patch Changes - -- [#3381](https://github.com/sst/sst/pull/3381) [`b9853e668`](https://github.com/sst/sst/commit/b9853e6680969a55a37174a0dbbfb5cab77b887e) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - Fixes Astro streaming - -## 2.28.0 - -### Patch Changes - -- [#3378](https://github.com/sst/sst/pull/3378) [`62c709d16`](https://github.com/sst/sst/commit/62c709d16a3c680f10eec22187c6dd1fedd64e89) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - AstroSite: fixes build bug introduced with astro-sst changes - -## 2.27.0 - -### Minor Changes - -- [#3363](https://github.com/sst/sst/pull/3363) [`3299f350f`](https://github.com/sst/sst/commit/3299f350f5e08843ea158d8beadc449d9cbc8d3a) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - AstroSite: support "hybrid" mode - -### Patch Changes - -- [#3363](https://github.com/sst/sst/pull/3363) [`3299f350f`](https://github.com/sst/sst/commit/3299f350f5e08843ea158d8beadc449d9cbc8d3a) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - AstriSite: improves SSR support - -- [#3363](https://github.com/sst/sst/pull/3363) [`3299f350f`](https://github.com/sst/sst/commit/3299f350f5e08843ea158d8beadc449d9cbc8d3a) Thanks [@bayssmekanique](https://github.com/bayssmekanique)! - AstroSite: handle redirect in CloudFront functions - -## 2.26.11 - -## 2.26.10 - -## 2.26.9 - -## 2.26.8 - -## 2.26.7 - -## 2.26.6 - -## 2.26.5 - -## 2.26.4 - -## 2.26.3 - -## 2.26.2 - -## 2.26.1 - -## 2.26.0 - -## 2.25.7 - -## 2.25.6 - -## 2.25.5 - -## 2.25.4 - -## 2.25.3 - -## 2.25.2 - -## 2.25.1 - -### Patch Changes - -- [#3216](https://github.com/sst/sst/pull/3216) [`49b68ef55`](https://github.com/sst/sst/commit/49b68ef55c45d7d9d787ed1b618a42dfbaf706e5) Thanks [@adamelmore](https://github.com/adamelmore)! - AstroSite: support streaming compression - -## 2.25.0 - -## 2.24.28 - -## 2.24.27 - -## 2.24.26 - -## 2.24.25 - -## 2.24.24 - -## 2.24.23 - -## 2.24.22 - -## 2.24.21 - -## 2.24.20 - -## 2.24.19 - -## 2.24.18 - -## 2.24.17 - -## 2.24.16 - -## 2.24.15 - -## 2.24.14 - -## 2.24.13 - -## 2.24.12 - -## 2.24.11 - -## 2.24.10 - -## 2.24.9 - -## 2.24.8 - -## 2.24.7 - -## 2.24.6 - -## 2.24.5 - -## 2.24.4 - -### Patch Changes - -- [#3220](https://github.com/sst/sst/pull/3220) [`a5c917183`](https://github.com/sst/sst/commit/a5c917183e0361781fbf69c34f72200cbf6af2ee) Thanks [@adamelmore](https://github.com/adamelmore)! - AstroSite: fix redirects for streaming response - -## 2.24.3 - -## 2.24.2 - -## 2.24.1 - -## 2.24.0 - -### Patch Changes - -- [#3201](https://github.com/sst/sst/pull/3201) [`f5a7d5609`](https://github.com/sst/sst/commit/f5a7d560930434b48d1970c7eddf3c5044caae58) Thanks [@jayair](https://github.com/jayair)! - Update serverless-stack to sst - -## 2.23.15 - -## 2.23.14 - -## 2.23.13 - -## 2.23.12 - -## 2.23.11 - -## 2.23.10 - -## 2.23.9 - -## 2.23.8 - -## 2.23.7 - -## 2.23.6 - -## 2.23.5 - -## 2.23.4 - -## 2.23.3 - -## 2.23.2 - -## 2.23.1 - -## 2.23.0 - -### Patch Changes - -- [#3177](https://github.com/serverless-stack/sst/pull/3177) [`8a31945c4`](https://github.com/serverless-stack/sst/commit/8a31945c44048308b5f8cf4cc7e5fe490eb835c9) Thanks [@fwang](https://github.com/fwang)! - AstroSite: support streaming - -## 2.22.11 - -## 2.22.10 - -## 2.22.9 - -## 2.22.8 - -## 2.22.7 - -## 2.22.6 - -## 2.22.5 - -## 2.22.4 - -## 2.22.3 - -## 2.22.2 - -## 2.22.1 - -## 2.22.0 - -## 2.21.8 - -## 2.21.7 - -## 2.21.6 - -## 2.21.5 - -## 2.21.4 - -## 2.21.3 - -## 2.21.2 - -## 2.21.1 - -## 2.21.0 - -## 2.20.1 - -## 2.20.0 - -## 2.19.2 - -## 2.19.1 - -## 2.19.0 - -## 2.18.4 - -## 2.18.3 - -## 2.18.2 - -## 2.18.1 - -## 2.18.0 - -## 2.17.8 - -## 2.17.7 - -## 2.17.6 - -## 2.17.5 - -## 2.17.4 - -## 2.17.3 - -## 2.17.2 - -## 2.17.1 - -## 2.17.0 - -## 2.16.4 - -## 2.16.3 - -## 2.16.2 - -## 2.16.1 - -## 2.16.0 - -## 2.15.0 - -## 2.14.0 - -## 2.13.9 - -## 2.13.8 - -## 2.13.7 - -## 2.13.6 - -## 2.13.5 - -## 2.13.4 - -## 2.13.3 - -## 2.13.2 - -## 2.13.1 - -## 2.13.0 - -## 2.12.2 - -## 2.12.1 - -## 2.12.0 - -## 2.11.18 - -## 2.11.17 - -## 2.11.16 - -## 2.11.15 - -## 2.11.14 - -## 2.11.13 - -## 2.11.12 - -## 2.11.11 - -## 2.11.10 - -## 2.11.9 - -## 2.11.8 - -## 2.11.7 - -## 2.11.6 - -## 2.11.5 - -## 2.11.4 - -## 2.11.3 - -## 2.11.2 - -## 2.11.1 - -## 2.11.0 - -## 2.10.4 - -## 2.10.3 - -## 2.10.2 - -## 2.10.1 - -## 2.10.0 - -## 2.9.0 - -## 2.8.29 - -## 2.8.28 - -## 2.8.27 - -## 2.8.26 - -## 2.8.25 - -## 2.8.24 - -## 2.8.23 - -## 2.8.22 - -## 2.8.21 - -## 2.8.20 - -## 2.8.19 - -## 2.8.18 - -## 2.8.17 - -## 2.8.16 - -## 2.8.15 - -## 2.8.14 - -## 2.8.13 - -## 2.8.12 - -## 2.8.11 - -## 2.8.10 - -## 2.8.9 - -## 2.8.8 - -## 2.8.7 - -## 2.8.6 - -## 2.8.5 - -## 2.8.4 - -## 2.8.3 - -## 2.8.2 - -## 2.8.1 - -## 2.8.0 - -## 2.7.2 - -## 2.7.1 - -## 2.7.0 - -## 2.6.0 - -## 2.5.8 - -## 2.5.7 - -## 2.5.6 - -## 2.5.5 - -## 2.5.4 - -## 2.5.3 - -## 2.5.2 - -## 2.5.1 - -## 2.5.0 - -## 2.4.3 - -## 2.4.2 - -## 2.4.1 - -## 2.4.0 - -## 2.3.7 - -## 2.3.6 - -## 2.3.5 - -## 2.3.4 - -## 2.3.3 - -## 2.3.2 - -## 2.3.1 - -## 2.3.0 - -## 2.2.8 - -## 2.2.7 - -## 2.2.6 - -## 2.2.5 - -## 2.2.4 - -## 2.2.3 - -## 2.2.2 - -## 2.2.1 - -## 2.2.0 - -## 2.1.35 - -## 2.1.34 - -## 2.1.33 - -## 2.1.32 - -## 2.1.31 - -## 2.1.30 - -## 2.1.29 - -### Patch Changes - -- [`1c5fe4976`](https://github.com/serverless-stack/sst/commit/1c5fe4976ccec198ca35548419af8f114e144b8c) Thanks [@thdxr](https://github.com/thdxr)! - Use latest astro - -## 2.1.28 - -## 2.1.27 - -## 2.1.26 - -## 2.1.25 - -## 2.1.24 - -## 2.1.23 - -## 2.1.22 - -## 2.1.21 - -## 2.1.20 - -## 2.1.19 - -## 2.1.18 - -## 2.1.17 - -## 2.1.16 - -## 2.1.15 - -## 2.1.14 - -## 2.1.13 - -## 2.1.12 - -## 2.1.11 - -## 2.1.10 - -### Patch Changes - -- [`d2e7d097d`](https://github.com/serverless-stack/sst/commit/d2e7d097d186c68c5ebde1bdd1c56a9de4f31787) Thanks [@fwang](https://github.com/fwang)! - SsrSite: set "x-forwarded-host" using CloudFront function - -## 2.1.9 - -## 2.1.8 - -## 2.1.7 - -## 2.1.6 - -## 2.1.5 - -## 2.1.4 - -## 2.1.3 - -## 2.1.2 - -## 2.1.1 - -## 2.1.0 - -## 2.0.39 - -## 2.0.38 - -## 2.0.37 - -## 2.0.36 - -### Patch Changes - -- [`d81ac9fae`](https://github.com/serverless-stack/sst/commit/d81ac9faecbca341f685082a9d1b6042886a288a) Thanks [@thdxr](https://github.com/thdxr)! - Fixed issue with astro adapter not forwarding cookies - -## 2.0.35 - -## 2.0.34 - -## 2.0.33 - -## 2.0.32 - -## 2.0.31 - -## 2.0.30 - -## 2.0.29 - -## 2.0.28 - -## 2.0.27 - -## 2.0.26 - -## 2.0.25 - -## 2.0.24 - -## 2.0.23 - -## 2.0.22 - -## 2.0.21 - -## 2.0.20 - -## 2.0.19 - -## 2.0.18 - -## 2.0.17 - -## 2.0.16 - -## 2.0.15 - -## 2.0.14 - -## 2.0.13 - -## 2.0.12 - -## 2.0.11 - -## 2.0.10 - -## 2.0.9 - -## 2.0.8 - -## 2.0.7 - -## 2.0.6 - -## 2.0.5 - -## 2.0.4 - -## 2.0.3 - -## 2.0.2 - -## 2.0.1 - -## 2.0.0 - -### Major Changes - -- [#2428](https://github.com/serverless-stack/sst/pull/2428) [`ce13bea66`](https://github.com/serverless-stack/sst/commit/ce13bea665ce80cfc5fb4a5b87e076e2f00ffece) Thanks [@thdxr](https://github.com/thdxr)! - SST 2.0 - - This is a major overhaul of the SST codebase primarily for ergonomics and performance. There should be no infrastructure changes however there are some project structure and package changes. Please view the upgrade guide here: https://docs.sst.dev/upgrade-guide - -## 2.0.0-rc.71 - -### Patch Changes - -- [`7688c39e1`](https://github.com/serverless-stack/sst/commit/7688c39e13c5470763cdbbad30ffcc3e579ed295) Thanks [@thdxr](https://github.com/thdxr)! - Update to astro 2.0 - -## 2.0.0-rc.18 - -### Patch Changes - -- [`738da5be5`](https://github.com/serverless-stack/sst/commit/738da5be5ecddbdead8d837aaafc18b553f9bc52) Thanks [@fwang](https://github.com/fwang)! - AstroSite: update adapter name to astro-sst - -## 2.0.0-rc.17 - -### Patch Changes - -- [`255dfbad2`](https://github.com/serverless-stack/sst/commit/255dfbad20e1fb2ecd3498cfc6c08dcce0106335) Thanks [@fwang](https://github.com/fwang)! - Sites: adapters for Astro and SolidStart diff --git a/packages/astro-sst/README.md b/packages/astro-sst/README.md deleted file mode 100644 index 978a34c74..000000000 --- a/packages/astro-sst/README.md +++ /dev/null @@ -1,100 +0,0 @@ -# astro-sst - -This adapter allows Astro to deploy your SSR or static site to [AWS](https://aws.amazon.com/). - -## Installation - -Add the AWS adapter to enable SST in your Astro project with the following `astro add` command. This will install the adapter and make the appropriate changes to your `astro.config.mjs` file in one step. - -```sh -# Using NPM -npx astro add astro-sst -# Using Yarn -yarn astro add astro-sst -# Using PNPM -pnpm astro add astro-sst -``` - -If you prefer to install the adapter manually instead, complete the following two steps: - -1. Install the AWS adapter to your project’s dependencies using your preferred package manager. If you’re using npm or aren’t sure, run this in the terminal: - - ```bash - npm install astro-sst - ``` - -1. Add two new lines to your `astro.config.mjs` project configuration file. - - ```js title="astro.config.mjs" ins={2, 5-6} - import { defineConfig } from "astro/config"; - import aws from "astro-sst"; - - export default defineConfig({ - output: "server", - adapter: aws(), - }); - ``` - -### Deployment Strategies - -You can utilize different deployment depending on your needs: - -- `regional`: SSR inside a [Lambda function](https://aws.amazon.com/lambda/) with [CloudFront](https://aws.amazon.com/cloudfront/) cached assets. (_default_) -- `edge`: SSR inside a [Lambda@Edge function](https://aws.amazon.com/lambda/edge/) with [CloudFront](https://aws.amazon.com/cloudfront/) cached assets. -- `static`: SSG assets deployed to [S3](https://aws.amazon.com/s3/) with [CloudFront](https://aws.amazon.com/cloudfront/) cached assets. - -You can change where to target by changing the import: - -```js title="astro.config.mjs" ins={2, 5-6} -import { defineConfig } from "astro/config"; -import aws from "astro-sst"; - -export default defineConfig({ - output: "server", - adapter: aws({ - deploymentStrategy: "edge", - }), -}); -``` - -### Response Mode - -When utilizing `regional` deployment strategy, you can choose how responses are handled: - -- `buffer`: Responses are buffered and sent as a single response. (_default_) -- `stream`: Responses are streamed as they are generated. - -```js title="astro.config.mjs" ins={2, 5-6} -import { defineConfig } from "astro/config"; -import aws from "astro-sst"; - -export default defineConfig({ - output: "server", - adapter: aws({ - deploymentStrategy: "regional", - responseMode: "stream", - }), -}); -``` - -### Server Routes - -When utilizing `regional` deployment strategy, server routes should be defined for any routes utilizing non-`GET` methods: - -```js title="astro.config.mjs" ins={2, 5-6} -import { defineConfig } from "astro/config"; -import aws from "astro-sst"; - -export default defineConfig({ - output: "server", - adapter: aws({ - deploymentStrategy: "regional", - serverRoutes: [ - "feedback", // Feedback page which requires POST method - "login", // Login page which requires POST method - "user/*", // Directory of user routes which are all SSR - "api/*", // Directory of API endpoints which require all methods - ], - }), -}); -``` diff --git a/packages/astro-sst/package.json b/packages/astro-sst/package.json deleted file mode 100644 index 0dad79679..000000000 --- a/packages/astro-sst/package.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "name": "astro-sst", - "description": "Adapter that allows Astro to deploy your site to AWS utilizing SST.", - "version": "2.45.1", - "type": "module", - "license": "MIT", - "author": { - "name": "SST", - "url": "https://sst.dev" - }, - "repository": { - "type": "git", - "url": "https://github.com/sst/v2.git", - "directory": "packages/astro-sst" - }, - "keywords": [ - "withastro", - "astro-adapter" - ], - "bugs": "https://github.com/sst/v2/issues", - "exports": { - ".": "./dist/adapter.js", - "./entrypoint": "./dist/entrypoint.js", - "./edge": "./dist/edge/adapter.js", - "./lambda": "./dist/lambda/adapter.js", - "./static": "./dist/static/adapter.js", - "./build-meta": "./dist/lib/build-meta.js", - "./package.json": "./package.json" - }, - "typesVersions": { - "*": { - "*": [ - "dist/adapter.d.ts" - ], - "edge": [ - "dist/edge/adapter.d.ts" - ], - "lambda": [ - "dist/lambda/adapter.d.ts" - ], - "static": [ - "dist/static/adapter.d.ts" - ], - "build-meta": [ - "dist/lib/build-meta.d.ts" - ] - } - }, - "scripts": { - "build": "tsc" - }, - "dependencies": { - "@astrojs/webapi": "^3.0.0", - "set-cookie-parser": "^2.6.0" - }, - "devDependencies": { - "@types/aws-lambda": "^8.10.130", - "@types/set-cookie-parser": "^2.4.7", - "astro": "4.2.6" - } -} diff --git a/packages/astro-sst/src/adapter.ts b/packages/astro-sst/src/adapter.ts deleted file mode 100644 index 4d87e3a5d..000000000 --- a/packages/astro-sst/src/adapter.ts +++ /dev/null @@ -1,157 +0,0 @@ -import type { AstroAdapter, AstroIntegration } from "astro"; -import type { - EntrypointParameters, - ResponseMode, - DeploymentStrategy, -} from "./lib/types.js"; -import { BuildMeta, IntegrationConfig } from "./lib/build-meta.js"; - -const PACKAGE_NAME = "astro-sst"; - -function getAdapter({ - deploymentStrategy, - responseMode, -}: { - deploymentStrategy: DeploymentStrategy; - responseMode: ResponseMode; -}): AstroAdapter { - const isStatic = deploymentStrategy === "static"; - - const baseConfig: AstroAdapter = { - name: PACKAGE_NAME, - serverEntrypoint: `${PACKAGE_NAME}/entrypoint`, - args: { responseMode }, - exports: ["handler"], - adapterFeatures: { - edgeMiddleware: false, - functionPerRoute: false, - }, - supportedAstroFeatures: { - staticOutput: "stable", - hybridOutput: "stable", - serverOutput: "stable", - assets: { - supportKind: "stable", - isSharpCompatible: true, - isSquooshCompatible: false, - }, - }, - }; - - return !isStatic - ? baseConfig - : { - name: baseConfig.name, - supportedAstroFeatures: { - ...baseConfig.supportedAstroFeatures, - assets: { - supportKind: "unsupported", - }, - }, - }; -} - -export default function createIntegration( - entrypointParameters: EntrypointParameters = {} -): AstroIntegration { - const integrationConfig: IntegrationConfig = { - deploymentStrategy: entrypointParameters.deploymentStrategy ?? "regional", - responseMode: entrypointParameters.responseMode ?? "buffer", - serverRoutes: entrypointParameters.serverRoutes ?? [], - }; - - if ( - integrationConfig.deploymentStrategy !== "regional" && - integrationConfig.responseMode === "stream" - ) { - throw new Error( - `Deployment strategy ${integrationConfig.deploymentStrategy} does not support streaming responses. Use 'buffer' response mode.` - ); - } - - return { - name: PACKAGE_NAME, - hooks: { - "astro:config:setup": ({ config, updateConfig }) => { - if ( - integrationConfig.deploymentStrategy !== "static" && - config.output === "static" - ) { - // If the user has not specified an output, we will allow the Astro config to override default deployment strategy. - if (typeof entrypointParameters.deploymentStrategy === "undefined") { - integrationConfig.deploymentStrategy = "static"; - } else { - console.log( - `[astro-sst] Overriding output to 'server' to support ${integrationConfig.deploymentStrategy} deployment.` - ); - updateConfig({ - output: "server", - }); - config.output = "server"; - } - } - - if ( - integrationConfig.deploymentStrategy === "static" && - config.output !== "static" - ) { - console.log( - `[astro-sst] Overriding output to 'static' to support ${integrationConfig.deploymentStrategy} deployment.` - ); - updateConfig({ - output: "static", - }); - config.output = "static"; - } - - if ( - config.output !== "static" && - config.image.service.entrypoint.endsWith("sharp") && - config.image.remotePatterns.length === 0 && - config.image.domains.length === 0 && - typeof config.site === "string" - ) { - const siteUrl = new URL(config.site); - updateConfig({ - image: { - remotePatterns: [ - { - protocol: siteUrl.protocol, - hostname: siteUrl.hostname, - port: siteUrl.port, - pathname: `${config.build.assets}/**`, - }, - ], - }, - }); - } - - if (config.output !== "static") { - // Enable sourcemaps for SSR builds. - updateConfig({ - vite: { - build: { - sourcemap: true, - }, - }, - }); - } - - BuildMeta.setIntegrationConfig(integrationConfig); - }, - "astro:config:done": ({ config, setAdapter }) => { - BuildMeta.setAstroConfig(config); - setAdapter( - getAdapter({ - deploymentStrategy: integrationConfig.deploymentStrategy, - responseMode: integrationConfig.responseMode, - }) - ); - }, - "astro:build:done": async (buildResults) => { - BuildMeta.setBuildResults(buildResults); - await BuildMeta.exportBuildMeta(); - }, - }, - }; -} diff --git a/packages/astro-sst/src/edge/adapter.ts b/packages/astro-sst/src/edge/adapter.ts deleted file mode 100644 index 94604b38f..000000000 --- a/packages/astro-sst/src/edge/adapter.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { AstroIntegration } from "astro"; -import defaultIntegration from "../adapter.js"; - -export default function createIntegration({} = {}): AstroIntegration { - console.warn( - `************************************************************************** -| !!! DEPRECATION WARNING !!!! -| The 'astro-sst/edge' adapter is deprecated. -| Please use 'astro-sst' adapter instead. -| ----------------------------------------------------------------------- -| import aws from "astro-sst"; -| -| export default defineConfig({ -| adapter: aws({ -| deploymentStrategy: "edge", -| }), -| }) -**************************************************************************` - ); - - return defaultIntegration({ - deploymentStrategy: "edge", - responseMode: "buffer", - }); -} diff --git a/packages/astro-sst/src/entrypoint.ts b/packages/astro-sst/src/entrypoint.ts deleted file mode 100644 index 2a1773a05..000000000 --- a/packages/astro-sst/src/entrypoint.ts +++ /dev/null @@ -1,169 +0,0 @@ -import type { SSRManifest } from "astro"; -import { version as ASTRO_VERSION } from "astro/package.json"; -import type { - APIGatewayProxyEventV2, - CloudFrontRequestEvent, -} from "aws-lambda"; -import type { RequestHandler, ResponseMode, ResponseStream } from "./lib/types"; -import { NodeApp } from "astro/app/node"; -import { polyfill } from "@astrojs/webapi"; -import { InternalEvent, convertFrom, convertTo } from "./lib/event-mapper.js"; -import { debug } from "./lib/logger.js"; -import { RenderOptions } from "astro/app"; - -const astroMajorVersion = parseInt(ASTRO_VERSION.split(".")[0] ?? 0); - -polyfill(globalThis, { - exclude: "window document", -}); - -declare global { - const awslambda: { - streamifyResponse(handler: RequestHandler): RequestHandler; - HttpResponseStream: { - from( - underlyingStream: ResponseStream, - metadata: { - statusCode: number; - headers?: Record; - } - ): ResponseStream; - }; - }; -} - -function createRequest(internalEvent: InternalEvent) { - const requestUrl = internalEvent.url; - const requestProps = { - method: internalEvent.method, - headers: internalEvent.headers, - body: ["GET", "HEAD"].includes(internalEvent.method) - ? undefined - : internalEvent.body, - }; - return new Request(requestUrl, requestProps); -} - -export function createExports( - manifest: SSRManifest, - { responseMode }: { responseMode: ResponseMode } -) { - debug("handlerInit", responseMode); - debug("astroVersion", ASTRO_VERSION); - const isStreaming = responseMode === "stream"; - const app = new NodeApp(manifest); - - async function streamHandler( - event: APIGatewayProxyEventV2, - responseStream: ResponseStream - ) { - debug("event", event); - - // Parse Lambda event - const internalEvent = convertFrom(event); - - // Build request - const request = createRequest(internalEvent); - - // Handle page not found - const routeData = app.match(request); - if (!routeData) { - return streamError(404, "Not found", responseStream); - } - - let response: Response; - - if (astroMajorVersion <= 3) { - // Astro 3.x and below use RouteData only - debug("routeData", routeData); - - // Process request - response = await app.render(request, routeData); - } else { - // Astro 4.x and above use RenderOptions - const renderOptions: RenderOptions = { - routeData, - clientAddress: internalEvent.headers['x-forwarded-for'] || internalEvent.remoteAddress, - } - - debug("renderOptions", renderOptions); - - // Process request - response = await app.render(request, renderOptions); - } - - // Stream response back to Cloudfront - const convertedResponse = await convertTo({ - type: internalEvent.type, - response, - responseStream, - cookies: Array.from(app.setCookieHeaders(response)), - }); - - debug("response", convertedResponse); - } - - async function bufferHandler( - event: APIGatewayProxyEventV2 | CloudFrontRequestEvent - ) { - debug("event", event); - - // Parse Lambda event - const internalEvent = convertFrom(event); - - // Build request - const request = createRequest(internalEvent); - - // Handle page not found - const routeData = app.match(request); - if (!routeData) { - console.error("Not found"); - return convertTo({ - type: internalEvent.type, - response: new Response("Not found", { status: 404 }), - }); - } - - const renderOptions: RenderOptions = { - routeData, - clientAddress: internalEvent.headers['x-forwarded-for'] || internalEvent.remoteAddress, - } - - debug("renderOptions", renderOptions); - - // Process request - const response = await app.render(request, renderOptions); - - // Buffer response back to Cloudfront - const convertedResponse = await convertTo({ - type: internalEvent.type, - response, - cookies: Array.from(app.setCookieHeaders(response)), - }); - - debug("response", convertedResponse); - return convertedResponse; - } - - return { - // https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html - handler: isStreaming - ? awslambda.streamifyResponse(streamHandler) - : bufferHandler, - }; -} - -export function streamError( - statusCode: number, - error: string | Error, - responseStream: ResponseStream -) { - console.error(error); - - responseStream = awslambda.HttpResponseStream.from(responseStream, { - statusCode, - }); - - responseStream.write(error.toString()); - responseStream.end(); -} diff --git a/packages/astro-sst/src/lambda/adapter.ts b/packages/astro-sst/src/lambda/adapter.ts deleted file mode 100644 index c1c63447c..000000000 --- a/packages/astro-sst/src/lambda/adapter.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type { AstroIntegration } from "astro"; -import defaultIntegration from "../adapter.js"; -import type { ResponseMode } from "../lib/types.js"; - -export default function createIntegration({ - responseMode, - serverRoutes, -}: { - responseMode?: ResponseMode; - serverRoutes?: string[]; -} = {}): AstroIntegration { - console.warn( - `************************************************************************** -| !!! DEPRECATION WARNING !!!! -| The 'astro-sst/lambda' adapter is deprecated. -| Please use 'astro-sst' adapter instead. -| ----------------------------------------------------------------------- -| import aws from "astro-sst"; -| -| export default defineConfig({ -| adapter: aws({ -| deploymentStrategy: "regional", -| serverRoutes: ["/api/*"], -| }), -| }) -**************************************************************************` - ); - - return defaultIntegration({ - deploymentStrategy: "regional", - responseMode: responseMode ?? "buffer", - serverRoutes: serverRoutes ?? [], - }); -} diff --git a/packages/astro-sst/src/lib/binary.ts b/packages/astro-sst/src/lib/binary.ts deleted file mode 100644 index 1b599022e..000000000 --- a/packages/astro-sst/src/lib/binary.ts +++ /dev/null @@ -1,64 +0,0 @@ -const commonBinaryMimeTypes = new Set([ - "application/octet-stream", - // Docs - "application/epub+zip", - "application/msword", - "application/pdf", - "application/rtf", - "application/vnd.amazon.ebook", - "application/vnd.ms-excel", - "application/vnd.ms-powerpoint", - "application/vnd.openxmlformats-officedocument.presentationml.presentation", - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - // Fonts - "font/otf", - "font/woff", - "font/woff2", - // Images - "image/bmp", - "image/gif", - "image/jpeg", - "image/png", - "image/tiff", - "image/vnd.microsoft.icon", - "image/webp", - // Audio - "audio/3gpp", - "audio/aac", - "audio/basic", - "audio/mpeg", - "audio/ogg", - "audio/wavaudio/webm", - "audio/x-aiff", - "audio/x-midi", - "audio/x-wav", - // Video - "video/3gpp", - "video/mp2t", - "video/mpeg", - "video/ogg", - "video/quicktime", - "video/webm", - "video/x-msvideo", - // Archives - "application/java-archive", - "application/vnd.apple.installer+xml", - "application/x-7z-compressed", - "application/x-apple-diskimage", - "application/x-bzip", - "application/x-bzip2", - "application/x-gzip", - "application/x-java-archive", - "application/x-rar-compressed", - "application/x-tar", - "application/x-zip", - "application/zip", -]); - -export function isBinaryContentType(contentType?: string | null) { - if (!contentType) return false; - - const value = contentType?.split(";")[0] ?? ""; - return commonBinaryMimeTypes.has(value); -} diff --git a/packages/astro-sst/src/lib/build-meta.ts b/packages/astro-sst/src/lib/build-meta.ts deleted file mode 100644 index 77d3e294b..000000000 --- a/packages/astro-sst/src/lib/build-meta.ts +++ /dev/null @@ -1,243 +0,0 @@ -import type { - AstroConfig, - RouteData, - RouteType, - ValidRedirectStatus, -} from "astro"; -import { join, relative } from "path"; -import { writeFile } from "fs/promises"; -import { fileURLToPath, parse } from "url"; -import type { - DeploymentStrategy, - OutputMode, - PageResolution, - ResponseMode, - TrailingSlash, -} from "./types"; - -export type BuildMetaFileName = "sst.buildMeta.json"; -export const BUILD_META_FILE_NAME: BuildMetaFileName = "sst.buildMeta.json"; - -type BuildResults = { - pages: { - pathname: string; - }[]; - dir: URL; - routes: RouteData[]; -}; - -type SerializableRoute = { - route: string; - type: RouteType; - pattern: string; - prerender?: boolean; - redirectPath?: string; - redirectStatus?: ValidRedirectStatus; -}; - -export type BuildMetaConfig = { - domainName?: string; - deploymentStrategy: DeploymentStrategy; - responseMode: ResponseMode; - outputMode: OutputMode; - pageResolution: PageResolution; - trailingSlash: TrailingSlash; - serverBuildOutputFile: string; - clientBuildOutputDir: string; - clientBuildVersionedSubDir: string; - serverRoutes: string[]; - routes: Array<{ - route: string; - type: RouteType; - pattern: string; - prerender?: boolean; - redirectPath?: string; - redirectStatus?: 300 | 301 | 302 | 303 | 304 | 307 | 308; - }>; -}; - -export type IntegrationConfig = { - deploymentStrategy: DeploymentStrategy; - responseMode: ResponseMode; - serverRoutes: string[]; -}; - -export class BuildMeta { - protected static integrationConfig: IntegrationConfig; - protected static astroConfig: AstroConfig; - protected static buildResults: BuildResults; - - public static setIntegrationConfig(config: IntegrationConfig) { - this.integrationConfig = config; - } - - public static setAstroConfig(config: AstroConfig) { - this.astroConfig = config; - } - - private static getRedirectPath( - { segments }: RouteData, - trailingSlash: TrailingSlash - ) { - let i = 0; - return ( - "/" + - segments - .map((segment) => - segment - .map((part) => (part.dynamic ? `\${${++i}}` : part.content)) - .join("") - ) - .join("/") + - (trailingSlash === "always" ? "/" : "") - ).replace(/\/+/g, "/"); - } - - public static setBuildResults(buildResults: BuildResults) { - this.buildResults = buildResults; - } - - private static get domainName() { - if ( - typeof this.astroConfig.site === "string" && - this.astroConfig.site.length > 0 - ) { - return parse(this.astroConfig.site).hostname ?? undefined; - } - } - - private static getSerializableRoute( - route: RouteData, - trailingSlash: TrailingSlash, - outputMode: OutputMode - ): SerializableRoute { - const isStatic = outputMode === "static"; - return { - route: route.route + (trailingSlash === "always" ? "/" : ""), - type: route.type, - pattern: route.pattern.toString(), - prerender: - route.type !== "redirect" ? isStatic || route.prerender : undefined, - redirectPath: - typeof route.redirectRoute !== "undefined" - ? BuildMeta.getRedirectPath(route.redirectRoute, trailingSlash) - : typeof route.redirect === "string" - ? route.redirect - : route.redirect?.destination, - redirectStatus: - typeof route.redirect === "object" ? route.redirect.status : undefined, - }; - } - - private static getTrailingSlashRedirect( - route: RouteData, - trailingSlash: "always" | "never" - ) { - if (trailingSlash === "never") { - return { - route: route.route + "/", - type: "redirect" as const, - pattern: route.pattern.toString().replace(/\$\/$/, "\\/$/"), - redirectPath: BuildMeta.getRedirectPath(route, trailingSlash), - }; - } - - return { - route: route.route.replace(/\/$/, ""), - type: "redirect" as const, - pattern: route.pattern.toString().replace(/\\\/\$\/$/, "$/"), - redirectPath: BuildMeta.getRedirectPath(route, trailingSlash), - }; - } - - public static async exportBuildMeta(buildExportName = BUILD_META_FILE_NAME) { - const rootDir = fileURLToPath(this.astroConfig.root); - - const outputPath = join( - relative(rootDir, fileURLToPath(this.astroConfig.outDir)), - buildExportName - ); - - const routes = this.buildResults.routes - .map((route) => { - const routeSet = [ - this.getSerializableRoute( - route, - this.astroConfig.trailingSlash, - this.astroConfig.output - ), - ]; - - if (route.type === "page" && route.route !== "/") { - if (this.astroConfig.trailingSlash === "never") { - routeSet.unshift( - this.getTrailingSlashRedirect( - route, - this.astroConfig.trailingSlash - ) - ); - } else if (this.astroConfig.trailingSlash === "always") { - routeSet.push( - this.getTrailingSlashRedirect( - route, - this.astroConfig.trailingSlash - ) - ); - } - } - - return routeSet; - }) - .flat(); - - if (this.astroConfig.output === "static") { - const lastAssetIndex = routes.reduce( - (acc, { route }, index) => - route.startsWith(`/${this.astroConfig.build.assets}`) ? index : acc, - -1 - ); - - routes.splice(lastAssetIndex + 1, 0, { - route: `/${this.astroConfig.build.assets}/[...slug]`, - type: "endpoint", - pattern: `/^\\/${this.astroConfig.build.assets}\\/.*?\\/?$/`, - prerender: true, - }); - } - - const buildMeta = { - domainName: this.domainName ?? undefined, - deploymentStrategy: this.integrationConfig.deploymentStrategy, - responseMode: this.integrationConfig.responseMode, - outputMode: this.astroConfig.output, - pageResolution: this.astroConfig.build.format, - trailingSlash: this.astroConfig.trailingSlash, - serverBuildOutputFile: join( - relative(rootDir, fileURLToPath(this.astroConfig.build.server)), - this.astroConfig.build.serverEntry - ), - clientBuildOutputDir: relative( - rootDir, - fileURLToPath(this.astroConfig.build.client) - ), - clientBuildVersionedSubDir: this.astroConfig.build.assets, - routes, - serverRoutes: this.integrationConfig.serverRoutes, - } satisfies BuildMetaConfig; - - /** - * For some reason the Astro integration system sets the following values - * as if the site was configured for server deployment even when it's - * actually configured for static. For this reason, we need to override these - * values as best we can. - **/ - if (this.astroConfig.output === "static") { - buildMeta.clientBuildOutputDir = join( - buildMeta.clientBuildOutputDir, - "../" - ); - } - - await writeFile(outputPath, JSON.stringify(buildMeta)); - } -} diff --git a/packages/astro-sst/src/lib/event-mapper.ts b/packages/astro-sst/src/lib/event-mapper.ts deleted file mode 100644 index 7f20ce9a9..000000000 --- a/packages/astro-sst/src/lib/event-mapper.ts +++ /dev/null @@ -1,486 +0,0 @@ -import type { - APIGatewayProxyEventV2, - APIGatewayProxyResultV2, - APIGatewayProxyEvent, - APIGatewayProxyResult, - CloudFrontRequestEvent, - CloudFrontRequestResult, - CloudFrontHeaders, -} from "aws-lambda"; -import type { ResponseStream } from "./types"; -import { splitCookiesString, parse, Cookie } from "set-cookie-parser"; -import { isBinaryContentType } from "./binary.js"; -import zlib from "zlib"; - -export type InternalEvent = { - readonly type: "v1" | "v2" | "cf"; - readonly method: string; - readonly queryString: string; - readonly rawPath: string; - readonly url: string; - readonly body: Buffer; - readonly headers: Record; - readonly remoteAddress: string; -}; - -type InternalResultInput = { - readonly type: "v1" | "v2" | "cf"; - response: Response; - responseStream?: ResponseStream; - cookies?: string[]; -}; - -type InternalResult = { - readonly type: "v1" | "v2" | "cf"; - statusCode: number; - headers: Record; - cookies: Cookie[]; - body: string; - isBase64Encoded: boolean; -}; - -type InternalStreamingResult = { - statusCode: number; - headers: Record; - cookies: Cookie[]; - body: ReadableStream | null; - responseStream: ResponseStream; - isBase64Encoded: boolean; -}; - -function isApigV2Event(event: any): event is APIGatewayProxyEventV2 { - return event.version === "2.0"; -} - -function isApigV1Event(event: any): event is APIGatewayProxyEvent { - return event.version === undefined && !isCfEvent(event); -} - -function isCfEvent(event: any): event is CloudFrontRequestEvent { - return event.Records !== undefined; -} - -export function convertFrom( - event: APIGatewayProxyEventV2 | APIGatewayProxyEvent | CloudFrontRequestEvent -) { - let iEvent: Omit; - if (isCfEvent(event)) { - iEvent = convertFromCfEvent(event); - } else if (isApigV2Event(event)) { - iEvent = convertFromApigV2Event(event); - } else if (isApigV1Event(event)) { - iEvent = convertFromApigV1Event(event); - } else { - throw new Error("Unsupported event type"); - } - - // Fix host header - if (iEvent.headers["x-forwarded-host"]) { - iEvent.headers.host = iEvent.headers["x-forwarded-host"]; - } - - // Build URL - const scheme = iEvent.headers["x-forwarded-protocol"] || "https"; - const url = new URL( - iEvent.queryString - ? `${iEvent.rawPath}?${iEvent.queryString}` - : iEvent.rawPath, - `${scheme}://${iEvent.headers.host}` - ).toString(); - - return { ...iEvent, url } satisfies InternalEvent; -} - -function convertFromApigV1Event(event: APIGatewayProxyEvent) { - const { path, body, httpMethod, requestContext, isBase64Encoded } = event; - const headers = normalizeApigV1Headers(event); - return { - type: "v1" as const, - method: httpMethod, - rawPath: path, - queryString: normalizeApigV1QueryParams(event), - body: Buffer.from(body ?? "", isBase64Encoded ? "base64" : "utf8"), - headers, - remoteAddress: requestContext.identity.sourceIp, - }; -} - -function convertFromApigV2Event(event: APIGatewayProxyEventV2) { - const { rawPath, rawQueryString, requestContext } = event; - return { - type: "v2" as const, - method: requestContext.http.method, - rawPath, - queryString: rawQueryString, - body: normalizeApigV2Body(event), - headers: normalizeApigV2Headers(event), - remoteAddress: requestContext.http.sourceIp, - }; -} - -function convertFromCfEvent(event: CloudFrontRequestEvent) { - const { method, uri, querystring, body, clientIp } = - event.Records[0].cf.request; - return { - type: "cf" as const, - method, - rawPath: uri, - queryString: querystring, - body: Buffer.from( - body?.data ?? "", - body?.encoding === "base64" ? "base64" : "utf8" - ), - headers: normalizeCfHeaders(event), - remoteAddress: clientIp, - }; -} - -export async function convertTo({ - type, - response, - responseStream, - cookies: appCookies, -}: InternalResultInput) { - // Parse headers (except cookies) - const headers: { [key: string]: string } = Array.from( - response.headers.entries() - ) - .filter(([key]) => key !== "set-cookie") - .reduce((headers, [key, value]) => { - headers[key] = value; - return headers; - }, {} as { [key: string]: string }); - - // Parse cookies - const cookies = parse( - [ - ...splitCookiesString(response.headers.getSetCookie() ?? undefined), - ...(appCookies ?? []), - ], - { decodeValues: false, map: false, silent: true } - ); - - // Parse isBase64Encoded - const isBase64Encoded = isBinaryContentType(headers["content-type"]); - - // Build streaming result - if (type === "v2" && responseStream) { - return convertToApigV2StreamingResult({ - statusCode: response.status, - headers, - body: response.body, - cookies, - responseStream, - isBase64Encoded, - }); - } - - // Build non-streaming result - const result = { - type, - statusCode: response.status, - headers, - cookies, - isBase64Encoded, - body: isBase64Encoded - ? Buffer.from(await response.arrayBuffer()).toString("base64") - : await response.text(), - }; - if (type === "v2") { - return convertToApigV2Result(result); - } else if (type === "v1") { - return convertToApigV1Result(result); - } else if (type === "cf") { - return convertToCfResult(result); - } - throw new Error("Unsupported event type"); -} - -function convertToApigV1Result({ - headers, - statusCode, - body, - isBase64Encoded, - cookies, -}: InternalResult): APIGatewayProxyResult { - const multiValueHeaders: Record = {}; - if (cookies.length > 0) { - multiValueHeaders["set-cookie"] = stringifyCookies(cookies); - } - - const response: APIGatewayProxyResult = { - statusCode, - headers, - multiValueHeaders, - body, - isBase64Encoded, - }; - - return response; -} - -function convertToApigV2Result({ - headers, - statusCode, - body, - isBase64Encoded, - cookies, -}: InternalResult): APIGatewayProxyResultV2 { - const response: APIGatewayProxyResultV2 = { - statusCode, - headers, - cookies: cookies.length > 0 ? stringifyCookies(cookies) : undefined, - body, - isBase64Encoded, - }; - - return response; -} - -function convertToApigV2StreamingResult({ - statusCode, - headers, - cookies, - body, - responseStream, - isBase64Encoded, -}: InternalStreamingResult) { - if (!isBase64Encoded) { - headers["content-encoding"] = "gzip"; - } - - const metadata = { - statusCode, - headers, - }; - if (cookies.length > 0) { - metadata.headers["set-cookie"] = stringifyCookies(cookies).join(", "); - } - responseStream = awslambda.HttpResponseStream.from(responseStream, metadata); - - if (!body) { - responseStream.write(0); - responseStream.end(); - return; - } - - if (body.locked) { - responseStream.write( - "Fatal error: Response body is locked. " + - `This can happen when the response was already read (for example through 'response.json()' or 'response.text()').` - ); - responseStream.end(); - return; - } - - const reader = body.getReader(); - - if (responseStream.destroyed) { - reader.cancel(); - return; - } - - let streamToWrite: ResponseStream | zlib.Gzip; - if (!isBase64Encoded) { - const gzip = zlib.createGzip(); - gzip.pipe(responseStream); - streamToWrite = gzip; - } else { - streamToWrite = responseStream; - } - - const cancel = (error?: Error) => { - streamToWrite.off("close", cancel); - streamToWrite.off("error", cancel); - - // If the reader has already been interrupted with an error earlier, - // then it will appear here, it is useless, but it needs to be catch. - reader.cancel(error).catch(() => {}); - - if (!isBase64Encoded) { - // Unpipe the gzip stream to ensure no more data is written - (streamToWrite as zlib.Gzip).unpipe(responseStream); - - if (error) { - streamToWrite.destroy(error); - } else { - // In case there's no error, just close the gzip stream - streamToWrite.end(); - } - } else if (error) { - responseStream.destroy(error); - } - }; - - streamToWrite.on("close", cancel); - streamToWrite.on("error", cancel); - - next(); - async function next() { - try { - for (;;) { - const { done, value } = await reader.read(); - if (done) break; - - if (!isBase64Encoded) { - const writer = streamToWrite as zlib.Gzip; - const result = writer.write(value, () => { - writer.flush(zlib.constants.Z_SYNC_FLUSH); - }); - if (!result) writer.once("drain", next); - } else { - if (!streamToWrite.write(value)) { - streamToWrite.once("drain", next); - return; - } - } - } - - streamToWrite.end(); - } catch (error) { - cancel(error instanceof Error ? error : new Error(String(error))); - } - } -} - -function convertToCfResult({ - statusCode, - headers, - cookies, - body, - isBase64Encoded, -}: InternalResult): CloudFrontRequestResult { - const combinedHeaders = Object.entries(headers).reduce( - (headers, [key, value]) => { - headers[key.toLowerCase()] = [{ key, value }]; - return headers; - }, - {} as CloudFrontHeaders - ); - combinedHeaders["set-cookie"] = stringifyCookies(cookies).map((cookie) => ({ - key: "set-cookie", - value: cookie, - })); - - const response: CloudFrontRequestResult = { - status: statusCode.toString(), - statusDescription: "OK", - headers: Object.entries(headers).reduce((headers, [key, value]) => { - headers[key.toLowerCase()] = [{ key, value }]; - return headers; - }, {} as CloudFrontHeaders), - bodyEncoding: isBase64Encoded ? "base64" : "text", - body: body, - }; - - return response; -} - -function normalizeApigV2Headers({ headers, cookies }: APIGatewayProxyEventV2) { - const combinedHeaders: Record = {}; - - if (Array.isArray(cookies)) { - combinedHeaders["cookie"] = cookies.join("; "); - } - - for (const [key, value] of Object.entries(headers ?? {})) { - combinedHeaders[key.toLowerCase()] = value!; - } - - return combinedHeaders; -} - -function normalizeApigV2Body({ - body, - isBase64Encoded, -}: APIGatewayProxyEventV2): Buffer { - if (Buffer.isBuffer(body)) { - return body; - } else if (typeof body === "string") { - return Buffer.from(body, isBase64Encoded ? "base64" : "utf8"); - } else if (typeof body === "object") { - return Buffer.from(JSON.stringify(body)); - } - return Buffer.from("", "utf8"); -} - -function normalizeApigV1QueryParams({ - multiValueQueryStringParameters, - queryStringParameters, -}: APIGatewayProxyEvent) { - const params = new URLSearchParams(); - for (const [key, value] of Object.entries( - multiValueQueryStringParameters ?? {} - )) { - if (value !== undefined) { - for (const v of value) { - params.append(key, v); - } - } - } - for (const [key, value] of Object.entries(queryStringParameters ?? {})) { - if (value !== undefined) { - params.append(key, value); - } - } - const value = params.toString(); - return value ?? ""; -} - -function normalizeApigV1Headers({ - multiValueHeaders, - headers, -}: APIGatewayProxyEvent) { - const combinedHeaders: Record = {}; - - for (const [key, values] of Object.entries(multiValueHeaders ?? {})) { - if (values) { - combinedHeaders[key.toLowerCase()] = values.join(","); - } - } - for (const [key, value] of Object.entries(headers ?? {})) { - if (value) { - combinedHeaders[key.toLowerCase()] = value; - } - } - - return combinedHeaders; -} - -function normalizeCfHeaders(event: CloudFrontRequestEvent) { - const combinedHeaders: Record = {}; - - for (const [key, values] of Object.entries( - event.Records[0].cf.request.headers - )) { - for (const { value } of values) { - if (value) { - combinedHeaders[key.toLowerCase()] = value; - } - } - } - - return combinedHeaders; -} - -function stringifyCookies(cookies: Cookie[]) { - return cookies.map( - (cookie) => - `${cookie.name}=${cookie.value};${Object.entries(cookie) - .filter( - ([key, value]) => - key !== "value" && - key !== "name" && - typeof value !== "undefined" && - value !== false - ) - .map(([key, value]) => - typeof value === "boolean" - ? `${key};` - : typeof value.toUTCString !== "undefined" - ? `${key}=${value.toUTCString()};` - : `${key}=${value};` - ) - .join("")}` - ); -} diff --git a/packages/astro-sst/src/lib/logger.ts b/packages/astro-sst/src/lib/logger.ts deleted file mode 100644 index 4fa836124..000000000 --- a/packages/astro-sst/src/lib/logger.ts +++ /dev/null @@ -1,5 +0,0 @@ -export function debug(...args: any[]) { - if (process.env.SST_DEBUG) { - console.log(...args.map((arg) => JSON.stringify(arg, null, 2))); - } -} diff --git a/packages/astro-sst/src/lib/types.ts b/packages/astro-sst/src/lib/types.ts deleted file mode 100644 index a4a790a74..000000000 --- a/packages/astro-sst/src/lib/types.ts +++ /dev/null @@ -1,32 +0,0 @@ -import type { APIGatewayProxyEventV2, Callback, Context } from "aws-lambda"; -import type { Writable } from "stream"; - -export interface ResponseStream extends Writable { - getBufferedData(): Buffer; - setContentType(contentType: string): void; -} - -export type RequestHandler = ( - event: APIGatewayProxyEventV2, - streamResponse: ResponseStream, - context?: Context, - callback?: Callback -) => void | Promise; - -export type EntrypointParameters = { - deploymentStrategy?: DeploymentStrategy; - responseMode?: ResponseMode; - serverRoutes?: string[]; -} & ( - | {} - | { responseMode: ResponseMode } - | { deploymentStrategy: "static"; responseMode?: "buffer" } - | { deploymentStrategy: "edge"; responseMode?: "buffer" } - | { deploymentStrategy: "regional"; responseMode?: ResponseMode } -); - -export type DeploymentStrategy = "edge" | "regional" | "static"; -export type ResponseMode = "stream" | "buffer"; -export type OutputMode = "server" | "static" | "hybrid"; -export type PageResolution = "file" | "directory"; -export type TrailingSlash = "never" | "always" | "ignore"; diff --git a/packages/astro-sst/src/static/adapter.ts b/packages/astro-sst/src/static/adapter.ts deleted file mode 100644 index c6eca76b6..000000000 --- a/packages/astro-sst/src/static/adapter.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { AstroIntegration } from "astro"; -import defaultIntegration from "../adapter.js"; - -export default function createIntegration({} = {}): AstroIntegration { - console.warn( - `************************************************************************** -| !!! DEPRECATION WARNING !!!! -| The 'astro-sst/static' adapter is deprecated. -| Please use 'astro-sst' adapter instead. -| ----------------------------------------------------------------------- -| import aws from "astro-sst"; -| -| export default defineConfig({ -| adapter: aws({ -| deploymentStrategy: "static", -| }), -| }) -**************************************************************************` - ); - - return defaultIntegration({ - deploymentStrategy: "static", - responseMode: "buffer", - }); -} diff --git a/packages/astro-sst/tsconfig.json b/packages/astro-sst/tsconfig.json deleted file mode 100644 index 2ea50d9f9..000000000 --- a/packages/astro-sst/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "include": ["src"], - "compilerOptions": { - "declaration": true, - "strict": true, - "moduleResolution": "node", - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "allowJs": true, - "resolveJsonModule": true, - "module": "ES2020", - "outDir": "./dist", - "target": "ES2020" - } -} diff --git a/packages/sst/src/cli/commands/update.ts b/packages/sst/src/cli/commands/update.ts index 4fc5a12c6..dabf96b05 100644 --- a/packages/sst/src/cli/commands/update.ts +++ b/packages/sst/src/cli/commands/update.ts @@ -1,7 +1,7 @@ import type { Program } from "../program.js"; const FIELDS = ["dependencies", "devDependencies"]; -const SST_PKGS = ["sst", "astro-sst", "svelte-kit-sst", "solid-start-sst"]; +const SST_PKGS = ["sst", "svelte-kit-sst", "solid-start-sst"]; type Packages = Set<[string, string]>; export const update = (program: Program) => diff --git a/www/package.json b/www/package.json index 3f4832334..b567af110 100644 --- a/www/package.json +++ b/www/package.json @@ -6,7 +6,7 @@ "docusaurus": "docusaurus", "start": "docusaurus start", "watch": "node ./generate.mjs watch", - "build": "cd ../packages/sst && pnpm run build && cd ../astro-sst && pnpm run build && cd ../../www && node ./generate.mjs build && docusaurus build", + "build": "cd ../packages/sst && pnpm run build && cd ../../www && node ./generate.mjs build && docusaurus build", "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy", "serve": "docusaurus serve",