Unverified Commit f536376f authored by Javi Velasco's avatar Javi Velasco Committed by GitHub

Ensure middleware order is preserved (#31801)

The order in which middleware must be invoked conditions its behaviour. Currently, this is not being taken into consideration for server since we are generating the array of middleware based on an arbitrary order of the middleware existing in the filesystem. This PR ships a change to generate the array of middleware preserving the order defined in the manifest.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
parent db099c56
...@@ -591,12 +591,14 @@ export default class Server { ...@@ -591,12 +591,14 @@ export default class Server {
protected getMiddleware() { protected getMiddleware() {
const middleware = this.middlewareManifest?.middleware || {} const middleware = this.middlewareManifest?.middleware || {}
return Object.keys(middleware).map((page) => ({ return (
match: getRouteMatcher( this.middlewareManifest?.sortedMiddleware.map((page) => ({
getMiddlewareRegex(page, MIDDLEWARE_ROUTE.test(middleware[page].name)) match: getRouteMatcher(
), getMiddlewareRegex(page, MIDDLEWARE_ROUTE.test(middleware[page].name))
page, ),
})) page,
})) || []
)
} }
protected async hasMiddleware( protected async hasMiddleware(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment