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

Status code in response set by middleware is not respected #12391

Open
1 task
Tobikblom opened this issue Nov 6, 2024 · 1 comment
Open
1 task

Status code in response set by middleware is not respected #12391

Tobikblom opened this issue Nov 6, 2024 · 1 comment
Labels
needs triage Issue needs to be triaged

Comments

@Tobikblom
Copy link

Astro Info

Astro                    v4.16.10
Node                     v20.10.0
System                   Windows (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/react
                         @astrojs/tailwind

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Given the following middleware, every request should respond with a Status Code 200 OK:

// middleware.ts
import { defineMiddleware, sequence } from "astro:middleware";

const ok = defineMiddleware(async (context, next) => {
  return new Response("OK", { status: 200 });
});


export const onRequest = sequence(ok);

However, sending a request to a pathname that is not matched by anything in the pages directory, will respond with a Status Code 404 Not Found, i.e., the response set by the middleware is not respected.

What's the expected result?

The Status Code set in the response by the middleware should be respected.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-bzdjbw?file=src%2Fmiddleware.ts

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Nov 6, 2024
@joshpensky
Copy link

We're having the same issue here — we use middleware to rewrite/forward requests from a path /www to our app

The request itself has a 200 OK response, but middleware always returns a 404 no matter what

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants