@astrojs/node
Advanced tools
Comparing version 0.0.0-error-overlay-20221203190718 to 0.0.0-experimental-assets-20230307131344
124
CHANGELOG.md
# @astrojs/node | ||
## 0.0.0-error-overlay-20221203190718 | ||
## 0.0.0-experimental-assets-20230307131344 | ||
### Minor Changes | ||
- [#6213](https://github.com/withastro/astro/pull/6213) [`afbbc4d5b`](https://github.com/withastro/astro/commit/afbbc4d5bfafc1779bac00b41c2a1cb1c90f2808) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Updated compilation settings to disable downlevelling for Node 14 | ||
### Patch Changes | ||
- Updated dependencies [[`8111a4b31`](https://github.com/withastro/astro/commit/8111a4b31615b26790cf1b69b9e8bf3c49cac492), [`3c44033e4`](https://github.com/withastro/astro/commit/3c44033e4ebafd28472d5c6a43e55c0363c6b555)]: | ||
- astro@0.0.0-error-overlay-20221203190718 | ||
- Updated dependencies [[`b087b83fe`](https://github.com/withastro/astro/commit/b087b83fe266c431fe34a07d5c2293cc4ab011c6), [`aacfe612f`](https://github.com/withastro/astro/commit/aacfe612fbb94713c1aa2131d23f6247d2c870de), [`a4a74ab70`](https://github.com/withastro/astro/commit/a4a74ab70cd2aa0d812a1f6b202c4e240a8913bf), [`75921b3cd`](https://github.com/withastro/astro/commit/75921b3cd916d439f6392c487c21532fde35ed13), [`afbbc4d5b`](https://github.com/withastro/astro/commit/afbbc4d5bfafc1779bac00b41c2a1cb1c90f2808)]: | ||
- astro@0.0.0-experimental-assets-20230307131344 | ||
- @astrojs/webapi@0.0.0-experimental-assets-20230307131344 | ||
## 5.0.4 | ||
### Patch Changes | ||
- [#6323](https://github.com/withastro/astro/pull/6323) [`5e26bc891`](https://github.com/withastro/astro/commit/5e26bc891cbebb3598acfa760c135a25c548d624) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Updated Undici to 5.20.0. This fixes a security issue and handling of cookies in certain cases in dev | ||
- Updated dependencies [[`5e26bc891`](https://github.com/withastro/astro/commit/5e26bc891cbebb3598acfa760c135a25c548d624), [`a156ecbb7`](https://github.com/withastro/astro/commit/a156ecbb7f4df6a46124a9a12eb712f9163db2ed), [`ccd72e6bb`](https://github.com/withastro/astro/commit/ccd72e6bb41e570d42b1b158e8124c8e04a1943d), [`504c7bacb`](https://github.com/withastro/astro/commit/504c7bacb8c1f2308a31e6c412825ba34983ba33), [`63dda6ded`](https://github.com/withastro/astro/commit/63dda6dedd4c6ea1d5ce72e9cf3fe5f88339a927), [`f91a7f376`](https://github.com/withastro/astro/commit/f91a7f376c223f18b4d8fbed81f95f6bea1cef8d)]: | ||
- astro@2.0.15 | ||
## 5.0.3 | ||
### Patch Changes | ||
- [#6110](https://github.com/withastro/astro/pull/6110) [`67ccec9e1`](https://github.com/withastro/astro/commit/67ccec9e168f241318d9dac40096016982d89b7b) Thanks [@matthewp](https://github.com/matthewp)! - Fixes support for prerendering and query params | ||
## 5.0.2 | ||
### Patch Changes | ||
- [#6088](https://github.com/withastro/astro/pull/6088) [`6a03649f0`](https://github.com/withastro/astro/commit/6a03649f0084f0df6738236d4a86c9936325cee7) Thanks [@QingXia-Ela](https://github.com/QingXia-Ela)! - fix incorrent encoded when path has other language characters | ||
## 5.0.1 | ||
### Patch Changes | ||
- [#5992](https://github.com/withastro/astro/pull/5992) [`60b32d585`](https://github.com/withastro/astro/commit/60b32d58565d87e87573eb268408293fc28ec657) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fix `Astro.url.protocol` when using the @astrojs/node SSR adapter with HTTPS | ||
- Updated dependencies [[`b53e0717b`](https://github.com/withastro/astro/commit/b53e0717b7f6b042baaeec7f87999e99c76c031c), [`60b32d585`](https://github.com/withastro/astro/commit/60b32d58565d87e87573eb268408293fc28ec657), [`883e0cc29`](https://github.com/withastro/astro/commit/883e0cc29968d51ed6c7515be035a40b28bafdad), [`dabce6b8c`](https://github.com/withastro/astro/commit/dabce6b8c684f851c3535f8acead06cbef6dce2a), [`aedf23f85`](https://github.com/withastro/astro/commit/aedf23f8582e32a6b94b81ddba9b323831f2b22a)]: | ||
- astro@2.0.2 | ||
## 5.0.0 | ||
### Major Changes | ||
- [#5782](https://github.com/withastro/astro/pull/5782) [`1f92d64ea`](https://github.com/withastro/astro/commit/1f92d64ea35c03fec43aff64eaf704dc5a9eb30a) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Remove support for Node 14. Minimum supported Node version is now >=16.12.0 | ||
- [#5707](https://github.com/withastro/astro/pull/5707) [`5eba34fcc`](https://github.com/withastro/astro/commit/5eba34fcc663def20bdf6e0daad02a6a5472776b) Thanks [@bluwy](https://github.com/bluwy)! - Remove `astro:build:start` backwards compatibility code | ||
- [#5806](https://github.com/withastro/astro/pull/5806) [`7572f7402`](https://github.com/withastro/astro/commit/7572f7402238da37de748be58d678fedaf863b53) Thanks [@matthewp](https://github.com/matthewp)! - Make astro a `peerDependency` of integrations | ||
This marks `astro` as a `peerDependency` of several packages that are already getting `major` version bumps. This is so we can more properly track the dependency between them and what version of Astro they are being used with. | ||
### Minor Changes | ||
- [#5832](https://github.com/withastro/astro/pull/5832) [`2303f9514`](https://github.com/withastro/astro/commit/2303f95142aa740c99213a098f82b99dd37d74a0) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Add support for serving well-known URIs with the @astrojs/node SSR adapter | ||
### Patch Changes | ||
- [#5701](https://github.com/withastro/astro/pull/5701) [`9869f2f6d`](https://github.com/withastro/astro/commit/9869f2f6d8c344babb8a59cb54918de14bd95dcc) Thanks [@wulinsheng123](https://github.com/wulinsheng123)! - Support custom 404 page in standalone mode | ||
- Updated dependencies [[`93e633922`](https://github.com/withastro/astro/commit/93e633922c2e449df3bb2357b3683af1d3c0e07b), [`16dc36a87`](https://github.com/withastro/astro/commit/16dc36a870df47a4151a8ed2d91d0bd1bb812458), [`01f3f463b`](https://github.com/withastro/astro/commit/01f3f463bf2918b310d130a9fabbf3ee21d14029), [`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144), [`05caf445d`](https://github.com/withastro/astro/commit/05caf445d4d2728f1010aeb2179a9e756c2fd17d), [`49ab4f231`](https://github.com/withastro/astro/commit/49ab4f231c23b34891c3ee86f4b92bf8d6d267a3), [`a342a486c`](https://github.com/withastro/astro/commit/a342a486c2831461e24e6c2f1ca8a9d3e15477b6), [`8fb28648f`](https://github.com/withastro/astro/commit/8fb28648f66629741cb976bfe34ccd9d8f55661e), [`1f92d64ea`](https://github.com/withastro/astro/commit/1f92d64ea35c03fec43aff64eaf704dc5a9eb30a), [`c2180746b`](https://github.com/withastro/astro/commit/c2180746b4f6d9ef1b6f86924f21f52cc6ab4e63), [`ae8a012a7`](https://github.com/withastro/astro/commit/ae8a012a7b6884a03c50494332ee37b4505c2c3b), [`cf2de5422`](https://github.com/withastro/astro/commit/cf2de5422c26bfdea4c75f76e57b57299ded3e3a), [`ce5c5dbd4`](https://github.com/withastro/astro/commit/ce5c5dbd46afbe738b03600758bf5c35113de522), [`ec09bb664`](https://github.com/withastro/astro/commit/ec09bb6642064dbd7d2f3369afb090363ae18de2), [`665a2c222`](https://github.com/withastro/astro/commit/665a2c2225e42881f5a9550599e8f3fc1deea0b4), [`259a539d7`](https://github.com/withastro/astro/commit/259a539d7d70c783330c797794b15716921629cf), [`f7aa1ec25`](https://github.com/withastro/astro/commit/f7aa1ec25d1584f7abd421903fbef66b1c050e2a), [`4987d6f44`](https://github.com/withastro/astro/commit/4987d6f44cfd0d81d88f21f5c380503403dc1e6a), [`304823811`](https://github.com/withastro/astro/commit/304823811eddd8e72aa1d8e2d39b40ab5cda3565), [`302e0ef8f`](https://github.com/withastro/astro/commit/302e0ef8f5d5232e3348afe680e599f3e537b5c5), [`55cea0a9d`](https://github.com/withastro/astro/commit/55cea0a9d8c8df91a46590fc04a9ac28089b3432), [`dd56c1941`](https://github.com/withastro/astro/commit/dd56c19411b126439b8bc42d681b6fa8c06e8c61), [`9963c6e4d`](https://github.com/withastro/astro/commit/9963c6e4d50c392c3d1ac4492237020f15ccb1de), [`46ecd5de3`](https://github.com/withastro/astro/commit/46ecd5de34df619e2ee73ccea39a57acd37bc0b8), [`be901dc98`](https://github.com/withastro/astro/commit/be901dc98c4a7f6b5536540aa8f7ba5108e939a0), [`f6cf92b48`](https://github.com/withastro/astro/commit/f6cf92b48317a19a3840ad781b77d6d3cae143bb), [`e818cc046`](https://github.com/withastro/astro/commit/e818cc0466a942919ea3c41585e231c8c80cb3d0), [`8c100a6fe`](https://github.com/withastro/astro/commit/8c100a6fe6cc652c3799d1622e12c2c969f30510), [`116d8835c`](https://github.com/withastro/astro/commit/116d8835ca9e78f8b5e477ee5a3d737b69f80706), [`840412128`](https://github.com/withastro/astro/commit/840412128b00a04515156e92c314a929d6b94f6d), [`1f49cddf9`](https://github.com/withastro/astro/commit/1f49cddf9e9ffc651efc171b2cbde9fbe9e8709d), [`7325df412`](https://github.com/withastro/astro/commit/7325df412107fc0e65cd45c1b568fb686708f723), [`16c7d0bfd`](https://github.com/withastro/astro/commit/16c7d0bfd49d2b9bfae45385f506bcd642f9444a), [`c55fbcb8e`](https://github.com/withastro/astro/commit/c55fbcb8edca1fe118a44f68c9f9436a4719d171), [`a9c292026`](https://github.com/withastro/astro/commit/a9c2920264e36cc5dc05f4adc1912187979edb0d), [`2a5786419`](https://github.com/withastro/astro/commit/2a5786419599b8674473c699300172b9aacbae2e), [`4a1cabfe6`](https://github.com/withastro/astro/commit/4a1cabfe6b9ef8a6fbbcc0727a0dc6fa300cedaa), [`a8d3e7924`](https://github.com/withastro/astro/commit/a8d3e79246605d252dcddad159e358e2d79bd624), [`fa8c131f8`](https://github.com/withastro/astro/commit/fa8c131f88ef67d14c62f1c00c97ed74d43a80ac), [`64b8082e7`](https://github.com/withastro/astro/commit/64b8082e776b832f1433ed288e6f7888adb626d0), [`c4b0cb8bf`](https://github.com/withastro/astro/commit/c4b0cb8bf2b41887d9106440bb2e70d421a5f481), [`1f92d64ea`](https://github.com/withastro/astro/commit/1f92d64ea35c03fec43aff64eaf704dc5a9eb30a), [`23dc9ea96`](https://github.com/withastro/astro/commit/23dc9ea96a10343852d965efd41fe6665294f1fb), [`63a6ceb38`](https://github.com/withastro/astro/commit/63a6ceb38d88331451dca64d0034c7c58e3d26f1), [`a3a7fc929`](https://github.com/withastro/astro/commit/a3a7fc9298e6d88abb4b7bee1e58f05fa9558cf1), [`52209ca2a`](https://github.com/withastro/astro/commit/52209ca2ad72a30854947dcb3a90ab4db0ac0a6f), [`5fd9208d4`](https://github.com/withastro/astro/commit/5fd9208d447f5ab8909a2188b6c2491a0debd49d), [`5eba34fcc`](https://github.com/withastro/astro/commit/5eba34fcc663def20bdf6e0daad02a6a5472776b), [`899214298`](https://github.com/withastro/astro/commit/899214298cee5f0c975c7245e623c649e1842d73), [`3a00ecb3e`](https://github.com/withastro/astro/commit/3a00ecb3eb4bc44be758c064f2bde6e247e8a593), [`5eba34fcc`](https://github.com/withastro/astro/commit/5eba34fcc663def20bdf6e0daad02a6a5472776b), [`2303f9514`](https://github.com/withastro/astro/commit/2303f95142aa740c99213a098f82b99dd37d74a0), [`1ca81c16b`](https://github.com/withastro/astro/commit/1ca81c16b8b66236e092e6eb6ec3f73f5668421c), [`b66d7195c`](https://github.com/withastro/astro/commit/b66d7195c17a55ea0931bc3744888bd4f5f01ce6)]: | ||
- astro@2.0.0 | ||
- @astrojs/webapi@2.0.0 | ||
## 5.0.0-beta.1 | ||
<details> | ||
<summary>See changes in 5.0.0-beta.1</summary> | ||
### Major Changes | ||
- [#5782](https://github.com/withastro/astro/pull/5782) [`1f92d64ea`](https://github.com/withastro/astro/commit/1f92d64ea35c03fec43aff64eaf704dc5a9eb30a) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Remove support for Node 14. Minimum supported Node version is now >=16.12.0 | ||
- [#5806](https://github.com/withastro/astro/pull/5806) [`7572f7402`](https://github.com/withastro/astro/commit/7572f7402238da37de748be58d678fedaf863b53) Thanks [@matthewp](https://github.com/matthewp)! - Make astro a `peerDependency` of integrations | ||
This marks `astro` as a `peerDependency` of several packages that are already getting `major` version bumps. This is so we can more properly track the dependency between them and what version of Astro they are being used with. | ||
### Minor Changes | ||
- [#5832](https://github.com/withastro/astro/pull/5832) [`2303f9514`](https://github.com/withastro/astro/commit/2303f95142aa740c99213a098f82b99dd37d74a0) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Add support for serving well-known URIs with the @astrojs/node SSR adapter | ||
### Patch Changes | ||
- [#5701](https://github.com/withastro/astro/pull/5701) [`9869f2f6d`](https://github.com/withastro/astro/commit/9869f2f6d8c344babb8a59cb54918de14bd95dcc) Thanks [@wulinsheng123](https://github.com/wulinsheng123)! - Support custom 404 page in standalone mode | ||
- Updated dependencies [[`01f3f463b`](https://github.com/withastro/astro/commit/01f3f463bf2918b310d130a9fabbf3ee21d14029), [`1f92d64ea`](https://github.com/withastro/astro/commit/1f92d64ea35c03fec43aff64eaf704dc5a9eb30a), [`c2180746b`](https://github.com/withastro/astro/commit/c2180746b4f6d9ef1b6f86924f21f52cc6ab4e63), [`ae8a012a7`](https://github.com/withastro/astro/commit/ae8a012a7b6884a03c50494332ee37b4505c2c3b), [`cf2de5422`](https://github.com/withastro/astro/commit/cf2de5422c26bfdea4c75f76e57b57299ded3e3a), [`ec09bb664`](https://github.com/withastro/astro/commit/ec09bb6642064dbd7d2f3369afb090363ae18de2), [`665a2c222`](https://github.com/withastro/astro/commit/665a2c2225e42881f5a9550599e8f3fc1deea0b4), [`f7aa1ec25`](https://github.com/withastro/astro/commit/f7aa1ec25d1584f7abd421903fbef66b1c050e2a), [`302e0ef8f`](https://github.com/withastro/astro/commit/302e0ef8f5d5232e3348afe680e599f3e537b5c5), [`840412128`](https://github.com/withastro/astro/commit/840412128b00a04515156e92c314a929d6b94f6d), [`1f49cddf9`](https://github.com/withastro/astro/commit/1f49cddf9e9ffc651efc171b2cbde9fbe9e8709d), [`c55fbcb8e`](https://github.com/withastro/astro/commit/c55fbcb8edca1fe118a44f68c9f9436a4719d171), [`4a1cabfe6`](https://github.com/withastro/astro/commit/4a1cabfe6b9ef8a6fbbcc0727a0dc6fa300cedaa), [`c4b0cb8bf`](https://github.com/withastro/astro/commit/c4b0cb8bf2b41887d9106440bb2e70d421a5f481), [`1f92d64ea`](https://github.com/withastro/astro/commit/1f92d64ea35c03fec43aff64eaf704dc5a9eb30a), [`23dc9ea96`](https://github.com/withastro/astro/commit/23dc9ea96a10343852d965efd41fe6665294f1fb), [`63a6ceb38`](https://github.com/withastro/astro/commit/63a6ceb38d88331451dca64d0034c7c58e3d26f1), [`52209ca2a`](https://github.com/withastro/astro/commit/52209ca2ad72a30854947dcb3a90ab4db0ac0a6f), [`2303f9514`](https://github.com/withastro/astro/commit/2303f95142aa740c99213a098f82b99dd37d74a0)]: | ||
- astro@2.0.0-beta.2 | ||
- @astrojs/webapi@2.0.0-beta.0 | ||
</details> | ||
## 5.0.0-beta.0 | ||
<details> | ||
<summary>See changes in 5.0.0-beta.0</summary> | ||
### Major Changes | ||
- [#5707](https://github.com/withastro/astro/pull/5707) [`5eba34fcc`](https://github.com/withastro/astro/commit/5eba34fcc663def20bdf6e0daad02a6a5472776b) Thanks [@bluwy](https://github.com/bluwy)! - Remove `astro:build:start` backwards compatibility code | ||
### Patch Changes | ||
- Updated dependencies [[`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144), [`8fb28648f`](https://github.com/withastro/astro/commit/8fb28648f66629741cb976bfe34ccd9d8f55661e), [`dd56c1941`](https://github.com/withastro/astro/commit/dd56c19411b126439b8bc42d681b6fa8c06e8c61), [`f6cf92b48`](https://github.com/withastro/astro/commit/f6cf92b48317a19a3840ad781b77d6d3cae143bb), [`16c7d0bfd`](https://github.com/withastro/astro/commit/16c7d0bfd49d2b9bfae45385f506bcd642f9444a), [`a9c292026`](https://github.com/withastro/astro/commit/a9c2920264e36cc5dc05f4adc1912187979edb0d), [`5eba34fcc`](https://github.com/withastro/astro/commit/5eba34fcc663def20bdf6e0daad02a6a5472776b), [`5eba34fcc`](https://github.com/withastro/astro/commit/5eba34fcc663def20bdf6e0daad02a6a5472776b)]: | ||
- astro@2.0.0-beta.0 | ||
</details> | ||
## 4.0.0 | ||
### Patch Changes | ||
- Updated dependencies [[`d85ec7484`](https://github.com/withastro/astro/commit/d85ec7484ce14a4c7d3f480da8f38fcb9aff388f), [`d2960984c`](https://github.com/withastro/astro/commit/d2960984c59af7b60a3ea472c6c58fb00534a8e6), [`31ec84797`](https://github.com/withastro/astro/commit/31ec8479721a1cd65538ec041458c5ffe8f50ee9), [`5ec0f6ed5`](https://github.com/withastro/astro/commit/5ec0f6ed55b0a14a9663a90a03428345baf126bd), [`dced4a8a2`](https://github.com/withastro/astro/commit/dced4a8a2657887ec569860d9862d20f695dc23a), [`6b156dd3b`](https://github.com/withastro/astro/commit/6b156dd3b467884839a571c53114aadf26fa4b0b)]: | ||
- astro@1.7.0 | ||
## 3.1.1 | ||
### Patch Changes | ||
- [#5560](https://github.com/withastro/astro/pull/5560) [`281ea9fc3`](https://github.com/withastro/astro/commit/281ea9fc344dec4348e398696e671f833334045b) Thanks [@natemoo-re](https://github.com/natemoo-re)! - Improve error message when serverEntrypoint does not exist | ||
- Updated dependencies [[`b2f0210c4`](https://github.com/withastro/astro/commit/b2f0210c400a547d3067fdae6d15663b827be3a6), [`02bb0a1cc`](https://github.com/withastro/astro/commit/02bb0a1ccd53e38157eec3a750160731fce64b9c), [`2bd23e454`](https://github.com/withastro/astro/commit/2bd23e454fc9559aa00b9a493772acd69ba9ce6c)]: | ||
- astro@1.6.15 | ||
## 3.1.0 | ||
@@ -11,0 +129,0 @@ |
@@ -5,2 +5,3 @@ import fs from "fs"; | ||
import send from "send"; | ||
import enableDestroy from "server-destroy"; | ||
import { fileURLToPath } from "url"; | ||
@@ -10,6 +11,8 @@ function createServer({ client, port, host, removeBase }, handler) { | ||
if (req.url) { | ||
const pathname = "/" + removeBase(req.url); | ||
const stream = send(req, encodeURI(pathname), { | ||
let pathname = removeBase(req.url); | ||
pathname = pathname[0] === "/" ? pathname : "/" + pathname; | ||
pathname = new URL(pathname, `http://${host}:${port}`).pathname; | ||
const stream = send(req, encodeURI(decodeURI(pathname)), { | ||
root: fileURLToPath(client), | ||
dotfiles: "deny" | ||
dotfiles: pathname.startsWith("/.well-known/") ? "allow" : "deny" | ||
}); | ||
@@ -47,2 +50,3 @@ let forwardError = false; | ||
httpServer.listen(port, host); | ||
enableDestroy(httpServer); | ||
const closed = new Promise((resolve, reject) => { | ||
@@ -61,3 +65,3 @@ httpServer.addListener("close", resolve); | ||
await new Promise((resolve, reject) => { | ||
httpServer.close((err) => err ? reject(err) : resolve(void 0)); | ||
httpServer.destroy((err) => err ? reject(err) : resolve(void 0)); | ||
}); | ||
@@ -64,0 +68,0 @@ } |
@@ -6,3 +6,3 @@ function getAdapter(options) { | ||
previewEntrypoint: "@astrojs/node/preview.js", | ||
exports: ["handler"], | ||
exports: ["handler", "startServer"], | ||
args: options | ||
@@ -15,3 +15,2 @@ }; | ||
} | ||
let needsBuildConfig = false; | ||
let _options; | ||
@@ -31,8 +30,7 @@ return { | ||
"astro:config:done": ({ setAdapter, config }) => { | ||
var _a, _b, _c; | ||
needsBuildConfig = !((_a = config.build) == null ? void 0 : _a.server); | ||
var _a, _b; | ||
_options = { | ||
...userOptions, | ||
client: (_b = config.build.client) == null ? void 0 : _b.toString(), | ||
server: (_c = config.build.server) == null ? void 0 : _c.toString(), | ||
client: (_a = config.build.client) == null ? void 0 : _a.toString(), | ||
server: (_b = config.build.server) == null ? void 0 : _b.toString(), | ||
host: config.server.host, | ||
@@ -45,8 +43,2 @@ port: config.server.port | ||
} | ||
}, | ||
"astro:build:start": ({ buildConfig }) => { | ||
if (needsBuildConfig) { | ||
_options.client = buildConfig.client.toString(); | ||
_options.server = buildConfig.server.toString(); | ||
} | ||
} | ||
@@ -53,0 +45,0 @@ } |
import type { NodeApp } from 'astro/app/node'; | ||
import type { IncomingMessage, ServerResponse } from 'http'; | ||
export default function (app: NodeApp): (req: IncomingMessage, res: ServerResponse, next?: ((err?: unknown) => void) | undefined) => Promise<void>; | ||
import type { Options } from './types'; | ||
export default function (app: NodeApp, mode: Options['mode']): (req: IncomingMessage, res: ServerResponse, next?: ((err?: unknown) => void) | undefined) => Promise<void>; |
import { responseIterator } from "./response-iterator"; | ||
function middleware_default(app) { | ||
function middleware_default(app, mode) { | ||
return async function(req, res, next) { | ||
try { | ||
const route = app.match(req); | ||
const route = mode === "standalone" ? app.match(req, { matchNotFound: true }) : app.match(req); | ||
if (route) { | ||
@@ -7,0 +7,0 @@ try { |
@@ -21,6 +21,12 @@ import { fileURLToPath } from "url"; | ||
} | ||
} catch (_err) { | ||
throw new Error( | ||
`The server entrypoint ${fileURLToPath} does not exist. Have you ran a build yet?` | ||
); | ||
} catch (err) { | ||
if (err.code === "ERR_MODULE_NOT_FOUND") { | ||
throw new Error( | ||
`The server entrypoint ${fileURLToPath( | ||
serverEntrypoint | ||
)} does not exist. Have you ran a build yet?` | ||
); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
@@ -27,0 +33,0 @@ const handler = (req, res) => { |
@@ -7,3 +7,3 @@ /** | ||
/// <reference types="node" /> | ||
import type { Response as NodeResponse } from 'node-fetch'; | ||
import type { Response as NodeResponse } from 'undici'; | ||
export declare function responseIterator<T>(response: Response | NodeResponse | Buffer): AsyncIterableIterator<T>; |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import type { SSRManifest } from 'astro'; | ||
import type { Options } from './types'; | ||
export declare function createExports(manifest: SSRManifest): { | ||
export declare function createExports(manifest: SSRManifest, options: Options): { | ||
handler: (req: import("http").IncomingMessage, res: import("http").ServerResponse<import("http").IncomingMessage>, next?: ((err?: unknown) => void) | undefined) => Promise<void>; | ||
startServer: () => { | ||
server: { | ||
host: string | undefined; | ||
port: number; | ||
closed(): Promise<void>; | ||
server: import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("https").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>; | ||
stop: () => Promise<void>; | ||
}; | ||
done: Promise<void>; | ||
}; | ||
}; | ||
export declare function start(manifest: SSRManifest, options: Options): void; |
@@ -8,6 +8,7 @@ import { polyfill } from "@astrojs/webapi"; | ||
}); | ||
function createExports(manifest) { | ||
function createExports(manifest, options) { | ||
const app = new NodeApp(manifest); | ||
return { | ||
handler: middleware(app) | ||
handler: middleware(app, options.mode), | ||
startServer: () => startServer(app, options) | ||
}; | ||
@@ -14,0 +15,0 @@ } |
@@ -0,4 +1,16 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import type { NodeApp } from 'astro/app/node'; | ||
import https from 'https'; | ||
import type { Options } from './types'; | ||
export declare function getResolvedHostForHttpServer(host: string | boolean): string | undefined; | ||
export default function startServer(app: NodeApp, options: Options): Promise<void>; | ||
export default function startServer(app: NodeApp, options: Options): { | ||
server: { | ||
host: string | undefined; | ||
port: number; | ||
closed(): Promise<void>; | ||
server: import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | https.Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>; | ||
stop: () => Promise<void>; | ||
}; | ||
done: Promise<void>; | ||
}; |
@@ -0,1 +1,2 @@ | ||
import https from "https"; | ||
import path from "path"; | ||
@@ -30,3 +31,3 @@ import { fileURLToPath } from "url"; | ||
const { client } = resolvePaths(options); | ||
const handler = middleware(app); | ||
const handler = middleware(app, options.mode); | ||
const host = getResolvedHostForHttpServer( | ||
@@ -44,4 +45,8 @@ process.env.HOST !== void 0 && process.env.HOST !== "" ? process.env.HOST : options.host | ||
); | ||
console.log(`Server listening on http://${host}:${port}`); | ||
return server.closed(); | ||
const protocol = server.server instanceof https.Server ? "https" : "http"; | ||
console.log(`Server listening on ${protocol}://${host}:${port}`); | ||
return { | ||
server, | ||
done: server.closed() | ||
}; | ||
} | ||
@@ -48,0 +53,0 @@ export { |
{ | ||
"name": "@astrojs/node", | ||
"description": "Deploy your site to a Node.js server", | ||
"version": "0.0.0-error-overlay-20221203190718", | ||
"version": "0.0.0-experimental-assets-20230307131344", | ||
"type": "module", | ||
@@ -27,16 +27,19 @@ "types": "./dist/index.d.ts", | ||
"dependencies": { | ||
"@astrojs/webapi": "^1.1.1", | ||
"send": "^0.18.0" | ||
"@astrojs/webapi": "0.0.0-experimental-assets-20230307131344", | ||
"send": "^0.18.0", | ||
"server-destroy": "^1.0.1" | ||
}, | ||
"peerDependencies": { | ||
"astro": "0.0.0-error-overlay-20221203190718" | ||
"astro": "0.0.0-experimental-assets-20230307131344" | ||
}, | ||
"devDependencies": { | ||
"@types/node-fetch": "^2.6.2", | ||
"@types/send": "^0.17.1", | ||
"astro": "0.0.0-error-overlay-20221203190718", | ||
"astro-scripts": "0.0.9", | ||
"@types/server-destroy": "^1.0.1", | ||
"astro": "0.0.0-experimental-assets-20230307131344", | ||
"astro-scripts": "0.0.0-experimental-assets-20230307131344", | ||
"chai": "^4.3.6", | ||
"cheerio": "^1.0.0-rc.11", | ||
"mocha": "^9.2.2", | ||
"node-mocks-http": "^1.11.0" | ||
"node-mocks-http": "^1.11.0", | ||
"undici": "^5.20.0" | ||
}, | ||
@@ -43,0 +46,0 @@ "scripts": { |
@@ -101,2 +101,23 @@ # @astrojs/node | ||
Or, with Fastify (>4): | ||
```js | ||
import Fastify from 'fastify'; | ||
import fastifyMiddie from '@fastify/middie'; | ||
import fastifyStatic from '@fastify/static'; | ||
import { fileURLToPath } from 'url'; | ||
import { handler as ssrHandler } from './dist/server/entry.mjs'; | ||
const app = Fastify({ logger: true }); | ||
await app | ||
.register(fastifyStatic, { | ||
root: fileURLToPath(new URL('./dist/client', import.meta.url)), | ||
}) | ||
.register(fastifyMiddie); | ||
app.use(ssrHandler); | ||
app.listen({ port: 8080 }); | ||
``` | ||
Note that middleware mode does not do file serving. You'll need to configure your HTTP framework to do that for you. By default the client assets are written to `./dist/client/`. | ||
@@ -103,0 +124,0 @@ |
@@ -5,2 +5,3 @@ import fs from 'fs'; | ||
import send from 'send'; | ||
import enableDestroy from 'server-destroy'; | ||
import { fileURLToPath } from 'url'; | ||
@@ -21,6 +22,8 @@ | ||
if (req.url) { | ||
const pathname = '/' + removeBase(req.url); | ||
const stream = send(req, encodeURI(pathname), { | ||
let pathname = removeBase(req.url); | ||
pathname = pathname[0] === '/' ? pathname : '/' + pathname; | ||
pathname = new URL(pathname, `http://${host}:${port}`).pathname; | ||
const stream = send(req, encodeURI(decodeURI(pathname)), { | ||
root: fileURLToPath(client), | ||
dotfiles: 'deny', | ||
dotfiles: pathname.startsWith('/.well-known/') ? 'allow' : 'deny', | ||
}); | ||
@@ -67,2 +70,3 @@ | ||
httpServer.listen(port, host); | ||
enableDestroy(httpServer); | ||
@@ -84,3 +88,3 @@ // Resolves once the server is closed | ||
await new Promise((resolve, reject) => { | ||
httpServer.close((err) => (err ? reject(err) : resolve(undefined))); | ||
httpServer.destroy((err) => (err ? reject(err) : resolve(undefined))); | ||
}); | ||
@@ -87,0 +91,0 @@ }, |
@@ -9,3 +9,3 @@ import type { AstroAdapter, AstroIntegration } from 'astro'; | ||
previewEntrypoint: '@astrojs/node/preview.js', | ||
exports: ['handler'], | ||
exports: ['handler', 'startServer'], | ||
args: options, | ||
@@ -20,3 +20,2 @@ }; | ||
let needsBuildConfig = false; | ||
let _options: Options; | ||
@@ -36,3 +35,2 @@ return { | ||
'astro:config:done': ({ setAdapter, config }) => { | ||
needsBuildConfig = !config.build?.server; | ||
_options = { | ||
@@ -51,11 +49,4 @@ ...userOptions, | ||
}, | ||
'astro:build:start': ({ buildConfig }) => { | ||
// Backwards compat | ||
if (needsBuildConfig) { | ||
_options.client = buildConfig.client.toString(); | ||
_options.server = buildConfig.server.toString(); | ||
} | ||
}, | ||
}, | ||
}; | ||
} |
@@ -5,4 +5,5 @@ import type { NodeApp } from 'astro/app/node'; | ||
import { responseIterator } from './response-iterator'; | ||
import type { Options } from './types'; | ||
export default function (app: NodeApp) { | ||
export default function (app: NodeApp, mode: Options['mode']) { | ||
return async function ( | ||
@@ -14,4 +15,4 @@ req: IncomingMessage, | ||
try { | ||
const route = app.match(req); | ||
const route = | ||
mode === 'standalone' ? app.match(req, { matchNotFound: true }) : app.match(req); | ||
if (route) { | ||
@@ -18,0 +19,0 @@ try { |
@@ -27,6 +27,12 @@ import type { CreatePreviewServer } from 'astro'; | ||
} | ||
} catch (_err) { | ||
throw new Error( | ||
`The server entrypoint ${fileURLToPath} does not exist. Have you ran a build yet?` | ||
); | ||
} catch (err) { | ||
if ((err as any).code === 'ERR_MODULE_NOT_FOUND') { | ||
throw new Error( | ||
`The server entrypoint ${fileURLToPath( | ||
serverEntrypoint | ||
)} does not exist. Have you ran a build yet?` | ||
); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
@@ -33,0 +39,0 @@ |
@@ -7,4 +7,4 @@ /** | ||
import type { Response as NodeResponse } from 'node-fetch'; | ||
import { Readable as NodeReadableStream } from 'stream'; | ||
import type { Response as NodeResponse } from 'undici'; | ||
@@ -11,0 +11,0 @@ interface NodeStreamIterator<T> { |
@@ -12,6 +12,7 @@ import { polyfill } from '@astrojs/webapi'; | ||
export function createExports(manifest: SSRManifest) { | ||
export function createExports(manifest: SSRManifest, options: Options) { | ||
const app = new NodeApp(manifest); | ||
return { | ||
handler: middleware(app), | ||
handler: middleware(app, options.mode), | ||
startServer: () => startServer(app, options), | ||
}; | ||
@@ -18,0 +19,0 @@ } |
import type { NodeApp } from 'astro/app/node'; | ||
import https from 'https'; | ||
import path from 'path'; | ||
@@ -40,3 +41,3 @@ import { fileURLToPath } from 'url'; | ||
const { client } = resolvePaths(options); | ||
const handler = middleware(app); | ||
const handler = middleware(app, options.mode); | ||
@@ -57,6 +58,11 @@ // Allow to provide host value at runtime | ||
const protocol = server.server instanceof https.Server ? 'https' : 'http'; | ||
// eslint-disable-next-line no-console | ||
console.log(`Server listening on http://${host}:${port}`); | ||
console.log(`Server listening on ${protocol}://${host}:${port}`); | ||
return server.closed(); | ||
return { | ||
server, | ||
done: server.closed(), | ||
}; | ||
} |
import nodejs from '../dist/index.js'; | ||
import { loadFixture, createRequestAndResponse, toPromise } from './test-utils.js'; | ||
import { loadFixture, createRequestAndResponse } from './test-utils.js'; | ||
import { expect } from 'chai'; | ||
@@ -20,3 +20,2 @@ | ||
const { handler } = await import('./fixtures/api-route/dist/server/entry.mjs'); | ||
let { req, res, done } = createRequestAndResponse({ | ||
@@ -28,7 +27,11 @@ method: 'POST', | ||
handler(req, res); | ||
req.send(JSON.stringify({ id: 2 })); | ||
let [buffer] = await done; | ||
let json = JSON.parse(buffer.toString('utf-8')); | ||
expect(json.length).to.equal(1); | ||
expect(json[0].name).to.equal('Broccoli Soup'); | ||
@@ -35,0 +38,0 @@ }); |
@@ -0,4 +1,4 @@ | ||
import { EventEmitter } from 'events'; | ||
import httpMocks from 'node-mocks-http'; | ||
import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js'; | ||
import httpMocks from 'node-mocks-http'; | ||
import { EventEmitter } from 'events'; | ||
@@ -31,3 +31,9 @@ /** | ||
return { req, res, done }; | ||
// Get the response as text | ||
const text = async () => { | ||
let chunks = await done; | ||
return buffersToString(chunks); | ||
}; | ||
return { req, res, done, text }; | ||
} | ||
@@ -37,2 +43,11 @@ | ||
return new Promise((resolve) => { | ||
// node-mocks-http doesn't correctly handle non-Buffer typed arrays, | ||
// so override the write method to fix it. | ||
const write = res.write; | ||
res.write = function (data, encoding) { | ||
if (ArrayBuffer.isView(data) && !Buffer.isBuffer(data)) { | ||
data = Buffer.from(data.buffer); | ||
} | ||
return write.call(this, data, encoding); | ||
}; | ||
res.on('end', () => { | ||
@@ -44,1 +59,10 @@ let chunks = res._getChunks(); | ||
} | ||
export function buffersToString(buffers) { | ||
let decoder = new TextDecoder(); | ||
let str = ''; | ||
for (const buffer of buffers) { | ||
str += decoder.decode(buffer); | ||
} | ||
return str; | ||
} |
@@ -6,6 +6,6 @@ { | ||
"allowJs": true, | ||
"module": "ES2020", | ||
"module": "ES2022", | ||
"outDir": "./dist", | ||
"target": "ES2020" | ||
"target": "ES2021" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92116
60
1436
189
4
9
13
7
+ Addedserver-destroy@^1.0.1
+ Added@astrojs/compiler@1.8.2(transitive)
+ Added@astrojs/markdown-remark@0.0.0-experimental-assets-20230307131344(transitive)
+ Added@astrojs/prism@0.0.0-experimental-assets-20230307131344(transitive)
+ Added@astrojs/telemetry@0.0.0-experimental-assets-20230307131344(transitive)
+ Added@astrojs/webapi@0.0.0-experimental-assets-20230307131344(transitive)
+ Added@esbuild/android-arm@0.18.20(transitive)
+ Added@esbuild/android-arm64@0.18.20(transitive)
+ Added@esbuild/android-x64@0.18.20(transitive)
+ Added@esbuild/darwin-arm64@0.18.20(transitive)
+ Added@esbuild/darwin-x64@0.18.20(transitive)
+ Added@esbuild/freebsd-arm64@0.18.20(transitive)
+ Added@esbuild/freebsd-x64@0.18.20(transitive)
+ Added@esbuild/linux-arm@0.18.20(transitive)
+ Added@esbuild/linux-arm64@0.18.20(transitive)
+ Added@esbuild/linux-ia32@0.18.20(transitive)
+ Added@esbuild/linux-loong64@0.18.20(transitive)
+ Added@esbuild/linux-mips64el@0.18.20(transitive)
+ Added@esbuild/linux-ppc64@0.18.20(transitive)
+ Added@esbuild/linux-riscv64@0.18.20(transitive)
+ Added@esbuild/linux-s390x@0.18.20(transitive)
+ Added@esbuild/linux-x64@0.18.20(transitive)
+ Added@esbuild/netbsd-x64@0.18.20(transitive)
+ Added@esbuild/openbsd-x64@0.18.20(transitive)
+ Added@esbuild/sunos-x64@0.18.20(transitive)
+ Added@esbuild/win32-arm64@0.18.20(transitive)
+ Added@esbuild/win32-ia32@0.18.20(transitive)
+ Added@esbuild/win32-x64@0.18.20(transitive)
+ Addedanymatch@3.1.3(transitive)
+ Addedastro@0.0.0-experimental-assets-20230307131344(transitive)
+ Addedbinary-extensions@2.3.0(transitive)
+ Addedbusboy@1.6.0(transitive)
+ Addedchokidar@3.6.0(transitive)
+ Addeddevalue@4.3.3(transitive)
+ Addedes-module-lexer@1.5.4(transitive)
+ Addedesbuild@0.18.20(transitive)
+ Addedestree-walker@3.0.3(transitive)
+ Addedgithub-slugger@2.0.0(transitive)
+ Addedimage-size@1.1.1(transitive)
+ Addedis-binary-path@2.1.0(transitive)
+ Addedmagic-string@0.27.0(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addedqueue@6.0.2(transitive)
+ Addedreaddirp@3.6.0(transitive)
+ Addedrollup@3.29.5(transitive)
+ Addedserver-destroy@1.0.1(transitive)
+ Addedstreamsearch@1.1.0(transitive)
+ Addedundici@5.20.0(transitive)
+ Addedvite@4.5.5(transitive)
- Removed@astrojs/compiler@0.29.19(transitive)
- Removed@astrojs/markdown-remark@1.2.0(transitive)
- Removed@astrojs/micromark-extension-mdx-jsx@1.0.3(transitive)
- Removed@astrojs/prism@1.0.2(transitive)
- Removed@astrojs/telemetry@1.0.1(transitive)
- Removed@astrojs/webapi@1.1.1(transitive)
- Removed@esbuild/android-arm@0.15.18(transitive)
- Removed@esbuild/linux-loong64@0.14.540.15.18(transitive)
- Removed@polka/url@1.0.0-next.28(transitive)
- Removed@proload/core@0.3.3(transitive)
- Removed@proload/plugin-tsm@0.2.1(transitive)
- Removed@types/acorn@4.0.6(transitive)
- Removed@types/estree-jsx@0.0.11.0.5(transitive)
- Removed@types/html-escaper@3.0.2(transitive)
- Removedacorn-jsx@5.3.2(transitive)
- Removedast-types@0.14.2(transitive)
- Removedastro@0.0.0-error-overlay-20221203190718(transitive)
- Removedboolean@3.2.0(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedcharacter-reference-invalid@2.0.1(transitive)
- Removeddata-uri-to-buffer@4.0.1(transitive)
- Removeddeepmerge@4.3.1(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removeddetect-node@2.1.0(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-module-lexer@0.10.5(transitive)
- Removedes6-error@4.1.1(transitive)
- Removedesbuild@0.14.540.15.18(transitive)
- Removedesbuild-android-64@0.14.540.15.18(transitive)
- Removedesbuild-android-arm64@0.14.540.15.18(transitive)
- Removedesbuild-darwin-64@0.14.540.15.18(transitive)
- Removedesbuild-darwin-arm64@0.14.540.15.18(transitive)
- Removedesbuild-freebsd-64@0.14.540.15.18(transitive)
- Removedesbuild-freebsd-arm64@0.14.540.15.18(transitive)
- Removedesbuild-linux-32@0.14.540.15.18(transitive)
- Removedesbuild-linux-64@0.14.540.15.18(transitive)
- Removedesbuild-linux-arm@0.14.540.15.18(transitive)
- Removedesbuild-linux-arm64@0.14.540.15.18(transitive)
- Removedesbuild-linux-mips64le@0.14.540.15.18(transitive)
- Removedesbuild-linux-ppc64le@0.14.540.15.18(transitive)
- Removedesbuild-linux-riscv64@0.14.540.15.18(transitive)
- Removedesbuild-linux-s390x@0.14.540.15.18(transitive)
- Removedesbuild-netbsd-64@0.14.540.15.18(transitive)
- Removedesbuild-openbsd-64@0.14.540.15.18(transitive)
- Removedesbuild-sunos-64@0.14.540.15.18(transitive)
- Removedesbuild-windows-32@0.14.540.15.18(transitive)
- Removedesbuild-windows-64@0.14.540.15.18(transitive)
- Removedesbuild-windows-arm64@0.14.540.15.18(transitive)
- Removedescape-string-regexp@4.0.0(transitive)
- Removedestree-util-is-identifier-name@2.1.0(transitive)
- Removedestree-util-visit@1.2.1(transitive)
- Removedfetch-blob@3.2.0(transitive)
- Removedformdata-polyfill@4.0.10(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedglobal-agent@3.0.0(transitive)
- Removedglobalthis@1.0.4(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.1.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhtml-entities@2.5.2(transitive)
- Removedis-alphabetical@2.0.1(transitive)
- Removedis-alphanumerical@2.0.1(transitive)
- Removedis-decimal@2.0.1(transitive)
- Removedis-hexadecimal@2.0.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedlilconfig@2.1.0(transitive)
- Removedmagic-string@0.25.9(transitive)
- Removedmatcher@3.0.0(transitive)
- Removedmdast-util-mdx-expression@1.3.2(transitive)
- Removedmdast-util-mdx-jsx@1.2.0(transitive)
- Removedmicromark-extension-mdx-expression@1.0.8(transitive)
- Removedmicromark-extension-mdx-md@1.0.1(transitive)
- Removedmicromark-factory-mdx-expression@1.0.9(transitive)
- Removedmicromark-util-events-to-acorn@1.2.3(transitive)
- Removedmrmime@2.0.0(transitive)
- Removednode-domexception@1.0.0(transitive)
- Removednode-fetch@3.3.2(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedparse-entities@4.0.1(transitive)
- Removedpath-browserify@1.0.1(transitive)
- Removedpostcss-load-config@3.1.4(transitive)
- Removedrecast@0.20.5(transitive)
- Removedroarr@2.15.4(transitive)
- Removedrollup@2.79.2(transitive)
- Removedsemver-compare@1.0.0(transitive)
- Removedserialize-error@7.0.1(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedsirv@2.0.4(transitive)
- Removedsource-map@0.6.1(transitive)
- Removedsourcemap-codec@1.4.8(transitive)
- Removedsprintf-js@1.1.3(transitive)
- Removedtotalist@3.0.1(transitive)
- Removedtsm@2.3.0(transitive)
- Removedunist-util-map@3.1.3(transitive)
- Removedunist-util-position-from-estree@1.1.2(transitive)
- Removedunist-util-remove-position@4.0.2(transitive)
- Removedvite@3.2.11(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)
- Removedyaml@1.10.2(transitive)
Updated@astrojs/webapi@0.0.0-experimental-assets-20230307131344