feat: build option extractMiddleware#7448
Merged
ematipico merged 4 commits intofeat/vercel-edge-middlewarefrom Jun 26, 2023
Merged
feat: build option extractMiddleware#7448ematipico merged 4 commits intofeat/vercel-edge-middlewarefrom
extractMiddleware#7448ematipico merged 4 commits intofeat/vercel-edge-middlewarefrom
Conversation
🦋 Changeset detectedLatest commit: ac4d948 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 |
26bbfda to
34154dc
Compare
Contributor
|
Happy to see this was maybe a smaller change. But it looks like from the code that if |
Member
Author
It seems there's no need, the code emitted will look like this: import { e as sequence, f as defineMiddleware } from './chunks/astro.52e57b1a.mjs';
const third = defineMiddleware(async (context, next) => {
if (context.request.url.includes('/broken-locals')) {
context.locals = {
fn() {},
};
} else if (context.request.url.includes('/does-nothing')) {
return undefined;
}
return next();
});
const second = defineMiddleware(async (context, next) => {
if (context.request.url.includes('/second')) {
context.locals.name = 'second';
} else if (context.request.url.includes('/redirect')) {
return context.redirect('/', 302);
}
return await next();
});
const onRequest = sequence(first, second);
export { onRequest };And it won't be imported by any page |
99f5d26 to
c097653
Compare
34154dc to
594401f
Compare
bluwy
reviewed
Jun 23, 2023
fe4336f to
7671c6e
Compare
7671c6e to
4f8da57
Compare
splitMiddlewareextractMiddleware
4f8da57 to
ac4d948
Compare
bluwy
reviewed
Jun 26, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
This PR adds a new build option called
build.extractMiddleware. This is an advanced option needed for integrations, and it will be used later on in the Vercel adapter.Testing
I created a small test case, asserting that the locals won't be rendered because the middleware it's not called.
Docs
If the team agrees, I'd like to skip the doc review for now, and review it only when the final code is ready to be merged on
main