Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can jump 404 when that page does not exist #5701

Merged
merged 19 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-snakes-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/node': patch
---

can jump 404 when that page does not exist
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 4 additions & 3 deletions packages/integrations/node/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import type { NodeApp } from 'astro/app/node';
import type { IncomingMessage, ServerResponse } from 'http';
import type { Readable } from 'stream';
import { responseIterator } from './response-iterator';
import type { Options } from './types';

export default function (app: NodeApp) {
export default function (app: NodeApp, options: Options) {
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
return async function (
req: IncomingMessage,
res: ServerResponse,
next?: (err?: unknown) => void
) {
try {
const route = app.match(req);

const route =
options.mode === 'standalone' ? app.match(req, { matchNotFound: true }) : app.match(req);
if (route) {
try {
const response = await app.render(req);
Expand Down
4 changes: 2 additions & 2 deletions packages/integrations/node/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ polyfill(globalThis, {
exclude: 'window document',
});

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),
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/node/src/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function getResolvedHostForHttpServer(host: string | boolean) {
export default function startServer(app: NodeApp, options: Options) {
const port = process.env.PORT ? Number(process.env.PORT) : options.port ?? 8080;
const { client } = resolvePaths(options);
const handler = middleware(app);
const handler = middleware(app, options);

// Allow to provide host value at runtime
const host = getResolvedHostForHttpServer(
Expand Down