Skip to content

Commit dfe2e22

Browse files
feat: deprecate NodeApp (#15535)
* move stuff around * deprecate * utils * usage * changesets * Update .changeset/good-clubs-cover.md * Update .changeset/polite-terms-shop.md * changeset * fix: lint
1 parent ce27e97 commit dfe2e22

File tree

30 files changed

+359
-266
lines changed

30 files changed

+359
-266
lines changed

.changeset/big-cups-drive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': major
3+
---
4+
5+
Deprecates `loadManifest()` and `loadApp()` from `astro/app/node` (Adapter API) - ([v6 upgrade guidance](https://v6.docs.astro.build/en/guides/upgrade-to/v6/#deprecated-loadmanifest-and-loadapp-from-astroappnode-adapter-api))

.changeset/good-clubs-cover.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'astro': minor
3+
---
4+
5+
Exports new `createRequest()` and `writeResponse()` utilities from `astro/app/node`
6+
7+
To replace the deprecated `NodeApp.createRequest()` and `NodeApp.writeResponse()` methods, the `astro/app/node` module now exposes new `createRequest()` and `writeResponse()` utilities. These can be used to convert a NodeJS `IncomingMessage` into a web-standard `Request` and stream a web-standard `Response` into a NodeJS `ServerResponse`:
8+
9+
```js
10+
import { createApp } from 'astro/app/entrypoint';
11+
import { createRequest, writeResponse } from 'astro/app/node';
12+
import { createServer } from 'node:http';
13+
14+
const app = createApp();
15+
16+
const server = createServer(async (req, res) => {
17+
const request = createRequest(req);
18+
const response = await app.render(request);
19+
await writeResponse(response, res);
20+
})
21+
```

.changeset/olive-dots-jam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes the types of `createApp()` exported from `astro/app/entrypoint`

.changeset/polite-terms-shop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': major
3+
---
4+
5+
Deprecates `NodeApp` from `astro/app/node` (Adapter API) - ([v6 upgrade guidance](https://v6.docs.astro.build/en/guides/upgrade-to/v6/#deprecated-nodeapp-from-astroappnode-adapter-api))
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import type { IncomingMessage, ServerResponse } from 'node:http';
2-
import type { SSRManifest } from 'astro';
3-
import { NodeApp } from 'astro/app/node';
2+
import { createApp } from 'astro/app/entrypoint';
3+
import { createRequest } from 'astro/app/node';
44

5-
export function createExports(manifest: SSRManifest) {
6-
const app = new NodeApp(manifest);
7-
return {
8-
handler: async (req: IncomingMessage, res: ServerResponse) => {
9-
const start = performance.now();
10-
await app.render(req);
11-
const end = performance.now();
12-
res.write(end - start + '');
13-
res.end();
14-
},
15-
};
5+
const app = createApp();
6+
7+
export async function handler(req: IncomingMessage, res: ServerResponse): Promise<void> {
8+
const start = performance.now();
9+
await app.render(
10+
createRequest(req, {
11+
allowedDomains: app.manifest.allowedDomains,
12+
}),
13+
);
14+
const end = performance.now();
15+
res.write(end - start + '');
16+
res.end();
1617
}

packages/astro/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@
4949
"./runtime/*": "./dist/runtime/*",
5050
"./config": "./dist/config/entrypoint.js",
5151
"./container": "./dist/container/index.js",
52-
"./app": "./dist/core/app/index.js",
53-
"./app/node": "./dist/core/app/node.js",
54-
"./app/entrypoint": "./dist/core/app/entrypoint.js",
55-
"./app/entrypoint/dev": "./dist/core/app/entrypoint/dev.js",
56-
"./app/entrypoint/prod": "./dist/core/app/entrypoint/prod.js",
57-
"./app/manifest": "./dist/core/app/manifest.js",
52+
"./app": "./dist/core/app/entrypoints/index.js",
53+
"./app/node": "./dist/core/app/entrypoints/node.js",
54+
"./app/entrypoint": "./dist/core/app/entrypoints/virtual/index.js",
55+
"./app/entrypoint/dev": "./dist/core/app/entrypoints/virtual/dev.js",
56+
"./app/entrypoint/prod": "./dist/core/app/entrypoints/virtual/prod.js",
57+
"./app/manifest": "./dist/core/app/entrypoints/manifest.js",
5858
"./entrypoints/prerender": "./dist/entrypoints/prerender.js",
5959
"./entrypoints/legacy": "./dist/entrypoints/legacy.js",
6060
"./client/*": "./dist/runtime/client/*",

packages/astro/src/core/app/entrypoint.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export type { RoutesList } from '../../../types/astro.js';
2+
export { App } from '../app.js';
3+
export { BaseApp, type RenderErrorOptions, type RenderOptions } from '../base.js';
4+
export { fromRoutingStrategy, toRoutingStrategy } from '../common.js';
5+
export { createConsoleLogger } from '../logging.js';
6+
export {
7+
deserializeManifest,
8+
deserializeRouteData,
9+
deserializeRouteInfo,
10+
serializeRouteData,
11+
serializeRouteInfo,
12+
} from '../manifest.js';
13+
export { AppPipeline } from '../pipeline.js';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export {
2+
type SerializedRouteData,
3+
deserializeManifest,
4+
deserializeRouteData,
5+
deserializeRouteInfo,
6+
serializeRouteData,
7+
serializeRouteInfo,
8+
} from '../manifest.js';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { NodeApp, loadApp, loadManifest, createRequest, writeResponse } from '../node.js';

0 commit comments

Comments
 (0)