-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Integration defined middleware #8869
Conversation
🦋 Changeset detectedLatest commit: 7d47004 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is blocked because it contains a minor
changeset. A reviewer will merge this at the next release if approved.
!preview integration-middleware |
|
This can be tried out with: npm install astro@next--integration-middleware Note that preview releases are temporary and are only intended to test out a feature. |
852ac0f
to
b68d770
Compare
if(typeof updatedSettings.middleware[order] === 'undefined') { | ||
throw new Error( | ||
`The "${integration.name}" integration is trying to add middleware but did not specify an order.` | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what default makes the most sense, but I wouldn't expect to be required to provide order
. For example, a middleware that adds a new route could really go anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I don't like having a default when it's not obvious what the default should be. It really depends on the use-case; if you are doing something that modifies the response you want to be in pre
, if you are adding locals then post
is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Matthew on this one. Since the order is essential and we can't guess what the user intends to do, I think we need to force the user to choose.
if(typeof updatedSettings.middleware[order] === 'undefined') { | ||
throw new Error( | ||
`The "${integration.name}" integration is trying to add middleware but did not specify an order.` | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Matthew on this one. Since the order is essential and we can't guess what the user intends to do, I think we need to force the user to choose.
Co-authored-by: Bjorn Lu <[email protected]>
Co-authored-by: Bjorn Lu <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @matthewp ! Just left some comments on the changeset!
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Emanuele Stoppa <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I'm really looking forward to having this feature shipped!
Co-authored-by: Bjorn Lu <[email protected]>
* Rebase * Use an empty module if there is no real middleware * Add debug logging * Use normalizePath * Add a better example in the changesetp * Update .changeset/khaki-glasses-raise.md Co-authored-by: Bjorn Lu <[email protected]> * Update .changeset/khaki-glasses-raise.md Co-authored-by: Bjorn Lu <[email protected]> * Update .changeset/khaki-glasses-raise.md Co-authored-by: Sarah Rainsberger <[email protected]> * Update .changeset/khaki-glasses-raise.md Co-authored-by: Sarah Rainsberger <[email protected]> * Update .changeset/khaki-glasses-raise.md Co-authored-by: Sarah Rainsberger <[email protected]> * Update .changeset/khaki-glasses-raise.md Co-authored-by: Sarah Rainsberger <[email protected]> * Update packages/astro/src/core/middleware/vite-plugin.ts Co-authored-by: Emanuele Stoppa <[email protected]> * Review comments * oops * Update .changeset/khaki-glasses-raise.md Co-authored-by: Bjorn Lu <[email protected]> --------- Co-authored-by: Bjorn Lu <[email protected]> Co-authored-by: Sarah Rainsberger <[email protected]> Co-authored-by: Emanuele Stoppa <[email protected]>
Changes
Testing
Docs