Skip to content

Only add x-fah-middleware header to routes that have middleware enabled #325

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

mathu97
Copy link
Collaborator

@mathu97 mathu97 commented Apr 8, 2025

Currently x-fah-middleware header is being added to all routes of an app that has a middleware file.

This PR updates the logic to only add x-fah-middleware header to routes that have middleware enabled. This is done by reading the middleware-manifest.json to get the routes that middleware is enabled on, and updating the routes-manifest.json file with the x-fah-middleware headers.

@mathu97 mathu97 marked this pull request as ready for review April 11, 2025 16:54
@mathu97 mathu97 changed the title Only add x-fah-middleware routes to routes that have middleware enabled Only add x-fah-middleware header to routes that have middleware enabled Apr 11, 2025
Copy link
Collaborator

@annajowang annajowang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm from me on good looking code

}
// Add the middleware header to all routes for which middleware is enabled
const middlewareManifest = loadMiddlewareManifest(appPath, distDir);
const rootMiddleware = middlewareManifest.middleware["/"];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesdaniels My assumption here was that we only need to look at the root key as NextJs now only supports middleware at the root directory. It used to support nested middleware while in beta which is why I think the API is like this.

Similar logic in Opennext AWS adapter: https://github.com/opennextjs/opennextjs-aws/blob/73281c958d43d865fdded0d5d86dd82747365fee/packages/open-next/src/core/routing/util.ts#L160-L174

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good assumption

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

Successfully merging this pull request may close these issues.

3 participants