Skip to content

Commit b90f33a

Browse files
florian-lefebvresarah11918ArmandPhilippot
authored
feat: deprecate NodeApp (#13271)
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> Co-authored-by: Armand Philippot <git@armand.philippot.eu>
1 parent 2cef977 commit b90f33a

File tree

2 files changed

+78
-90
lines changed

2 files changed

+78
-90
lines changed

src/content/docs/en/guides/upgrade-to/v6.mdx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ Integration and adapter maintainers should pay special attention to changes affe
112112
- [generating routes with `RouteData`](#removed-routedatagenerate-adapter-api)
113113
- [routes with percent-encoded percent signs (e.g. `%25`)](#removed-percent-encoding-in-routes)
114114
- [`astro:ssr-manifest` virtual module](#removed-astrossr-manifest-virtual-module-integration-api)
115+
- [`NodeApp` from `astro/app/node`](#deprecated-nodeapp-from-astroappnode-adapter-api)
116+
- [`loadManifest()` and `loadApp()` from `astro/app/node`](#deprecated-loadmanifest-and-loadapp-from-astroappnode-adapter-api)
115117
- [`createExports()` and `start()`](#deprecated-createexports-and-start-adapter-api)
116118

117119
### Zod 4
@@ -375,6 +377,70 @@ export default defineConfig({
375377

376378
<ReadMore>Learn more about [available session drivers](/en/reference/session-driver-reference/#building-a-session-driver).</ReadMore>
377379

380+
### Deprecated: `NodeApp` from `astro/app/node` (Adapter API)
381+
382+
<SourcePR number="15535" title="feat: deprecate NodeApp" />
383+
384+
In Astro 5.x, adapters could implement their server entrypoint using `App` for standard web requests/responses, or `NodeApp` for node requests/responses.
385+
386+
Astro 6.0 deprecates `NodeApp` in favor of `createApp()` and new utilities: `createRequest()` and `writeResponse()`. This allows a more consistent API while preserving the same features as before. It also deprecates the `NodeAppHeadersJson` type.
387+
388+
#### What should I do?
389+
390+
If you have built an adapter, update any usage of `NodeApp` with `createApp()`:
391+
392+
```js title="my-adapter/server.js" del={1-12} ins={13-22}
393+
import { NodeApp } from 'astro/app/node';
394+
395+
export function createExports(manifest) {
396+
const app = new NodeApp(manifest);
397+
398+
const handler = async (req, res) => {
399+
const response = await app.render(req);
400+
await NodeApp.writeResponse(response, res);
401+
};
402+
403+
return { handler };
404+
}
405+
import { createApp } from 'astro/app/entrypoint';
406+
import { createRequest, writeResponse } from 'astro/app/node';
407+
408+
const app = createApp();
409+
410+
export const handler = async (req, res) => {
411+
const request = createRequest(req);
412+
const response = await app.render(request);
413+
await writeResponse(response, res);
414+
}
415+
```
416+
417+
<ReadMore>Learn more about [the `astro/app/node` module](/en/reference/adapter-reference/#astroappnode).</ReadMore>
418+
419+
### Deprecated: `loadManifest()` and `loadApp()` from `astro/app/node` (Adapter API)
420+
421+
<SourcePR number="15535" title="feat: deprecate NodeApp" />
422+
423+
In Astro 5.x, the `astro/app/node` exposed `loadManifest()` and `loadApp()` utilities to allow loading the SSR manifest or a `NodeApp` instance from a `URL` instance. However, these were not documented and are no longer recommended usage with the v6 Adapter API.
424+
425+
Astro 6.0 deprecates both functions.
426+
427+
#### What should I do?
428+
429+
If you have built an adapter, remove `loadManifest()` and replace `loadApp()` by `createApp()`:
430+
431+
```js title="my-adapter/server.js" del={1-5} ins={6-8}
432+
import { loadManifest, loadApp, NodeApp } from 'astro/app/node';
433+
434+
const manifest = await loadManifest(new URL(import.meta.url));
435+
const app1 = new NodeApp(loadManifest);
436+
const app2 = await loadApp(new URL(import.meta.url));
437+
import { createApp } from 'astro/app/entrypoint';
438+
439+
const app = createApp();
440+
```
441+
442+
<ReadMore>Learn more about [the `astro/app/entrypoint` module](/en/reference/adapter-reference/#astroappentrypoint).</ReadMore>
443+
378444
### Deprecated: `createExports()` and `start()` (Adapter API)
379445
380446
<SourcePR number="15461" title="feat: improve naming of new adapter api" />

src/content/docs/en/reference/adapter-reference.mdx

Lines changed: 12 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -812,128 +812,50 @@ addEventListener('fetch', (event) => {
812812
813813
### `astro/app/node`
814814
815-
Just like [`astro/app`](#astroapp), this module is used for rendering pages that have been prebuilt through `astro build`. This allows you to create a `NodeApp` providing all the methods available from `App` and additional methods useful for Node environments.
815+
This module is used in conjunction with [`astro/app`](#astroapp) to convert a NodeJS `IncomingMessage` into a web-standard `Request` and stream a web-standard `Response` into a NodeJS `ServerResponse`.
816816
817-
The `NodeApp` constructor accepts a required SSR manifest argument, and optionally an argument to enable or disable streaming, defaulting to `true`.
818-
819-
```js
820-
import { NodeApp } from 'astro/app/node';
821-
import http from 'http';
822-
823-
const nodeApp = new NodeApp(manifest);
824-
825-
addEventListener('fetch', event => {
826-
event.respondWith(
827-
nodeApp.render(event.request)
828-
);
829-
});
830-
```
831-
832-
The following additional methods are provided:
833-
834-
#### `nodeApp.render()`
835-
836-
<p>
837-
838-
**Type:** `(request: NodeRequest | Request, options?: RenderOptions) => Promise<Response>`<br />
839-
<Since v="4.0.0" />
840-
</p>
841-
842-
Extends [`app.render()`](#apprender) to also accept [Node.js `IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) objects in addition to standard `Request` objects as the first argument. The second argument is an optional object allowing you to [control the rendering](#renderoptions).
843-
844-
```js
845-
const response = await nodeApp.render(request);
846-
```
847-
848-
#### `nodeApp.match()`
849-
850-
<p>
851-
852-
**Type:** `(req: NodeRequest | Request, allowPrerenderedRoutes?: boolean) => RouteData | undefined`
853-
</p>
854-
855-
Extends [`app.match()`](#appmatch) to also accept [Node.js `IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) objects in addition to standard `Request` objects.
856-
857-
```js
858-
if(nodeApp.match(request)) {
859-
const response = await nodeApp.render(request);
860-
}
861-
```
862-
863-
#### `nodeApp.headersMap`
864-
865-
<p>
866-
867-
**Type:** `NodeAppHeadersJson | undefined`<br />
868-
**Default:** `undefined`<br />
869-
<Since v="5.11.0" />
870-
</p>
871-
872-
An array containing the headers configuration. Each entry maps a pathname to a list of headers that should be applied for that route. This is useful for applying headers such as CSP directives to prerendered routes.
873-
874-
#### `nodeApp.setHeadersMap()`
875-
876-
<p>
877-
878-
**Type:** `(headers: NodeAppHeadersJson) => void`<br />
879-
<Since v="5.11.0" />
880-
</p>
881-
882-
Loads [headers configuration](#nodeappheadersmap) into the `NodeApp` instance.
883-
884-
```js
885-
nodeApp.setHeadersMap([
886-
{
887-
pathname: "/blog",
888-
headers: [
889-
{ key: "Content-Security-Policy", value: "default-src 'self'" },
890-
]
891-
}
892-
]);
893-
```
894-
895-
#### `NodeApp.createRequest()`
817+
#### `createRequest()`
896818
897819
<p>
898820
899821
**Type:** `(req: NodeRequest, options?: { skipBody?: boolean; allowedDomains?: Partial<RemotePattern>[]; }) => Request`<br />
900-
<Since v="4.2.0" />
822+
<Since v="6.0.0" />
901823
</p>
902824
903-
Converts a NodeJS `IncomingMessage` into a standard `Request` object. This static method accepts an optional object as the second argument, allowing you to define if the body should be ignored, defaulting to `false`, and the [`allowedDomains`](/en/reference/configuration-reference/#securityalloweddomains).
825+
Converts a NodeJS `IncomingMessage` into a standard `Request` object. This function accepts an optional object as the second argument, allowing you to define if the body should be ignored, defaulting to `false`, and the [`allowedDomains`](/en/reference/configuration-reference/#securityalloweddomains).
904826
905827
The following example creates a `Request` and passes it to `app.render()`:
906828
907829
```js {5}
908-
import { NodeApp } from 'astro/app/node';
830+
import { createRequest } from 'astro/app/node';
909831
import { createServer } from 'node:http';
910832

911833
const server = createServer(async (req, res) => {
912-
const request = NodeApp.createRequest(req);
834+
const request = createRequest(req);
913835
const response = await app.render(request);
914836
})
915837
```
916838
917-
#### `NodeApp.writeResponse()`
839+
#### `writeResponse()`
918840
919841
<p>
920842
921843
**Type:** `(source: Response, destination: ServerResponse) => Promise<ServerResponse<IncomingMessage> | undefined>`<br />
922-
<Since v="4.2.0" />
844+
<Since v="6.0.0" />
923845
</p>
924846
925-
Streams a web-standard `Response` into a NodeJS server response. This static method takes a `Response` object and the initial `ServerResponse` before returning a promise of a `ServerResponse` object.
847+
Streams a web-standard `Response` into a NodeJS server response. This function takes a `Response` object and the initial `ServerResponse` before returning a promise of a `ServerResponse` object.
926848
927849
The following example creates a `Request`, passes it to `app.render()`, and writes the response:
928850
929851
```js {7}
930-
import { NodeApp } from 'astro/app/node';
852+
import { createRequest, writeResponse } from 'astro/app/node';
931853
import { createServer } from 'node:http';
932854

933855
const server = createServer(async (req, res) => {
934-
const request = NodeApp.createRequest(req);
856+
const request = createRequest(req);
935857
const response = await app.render(request);
936-
await NodeApp.writeResponse(response, res);
858+
await writeResponse(response, res);
937859
})
938860
```
939861

0 commit comments

Comments
 (0)