-
Notifications
You must be signed in to change notification settings - Fork 90
feat: don't move files to CDN if they match middleware #812
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
Conversation
} | ||
|
||
const matchMiddleware = (middleware, filePath) => | ||
middleware.includes('') || |
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 don't have enough context to understand this check. Can you share an example of the shape middleware
can take?
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.
Ah, never mind. I think I figured it out by looking at the tests.
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.
It's an array of paths, relative to the site root, that indicate directories which have middleware. Next.js applies middleware to any path below that. The leading slash has been stripped. There are some examples in the unit tests. An empty string indicates root-level middleware thata applies to everything
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.
LGTM! Left minor comments, none blocking.
console.log( | ||
yellowBright(outdent`Skipped moving ${matchedPages.size} ${ | ||
matchedPages.size === 1 ? 'file because it matches' : 'files because they match' | ||
} middleware, so cannot be deployed to the CDN and will be served from the origin instead. This is fine, but we're letting you know because it may not be what you expect. |
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.
👌🏻
|
||
`, | ||
) | ||
// There could potentially be thousands of matching pages, so we don't want to spam the console with this |
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.
Is it fine not to show any pages at all when this happens? Is it worth showing something like "The following files and X others matched middlware (...)", or is that overkill?
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.
Hmm, possibly, though I'm not sure if that's useful information.
} | ||
|
||
const matchMiddleware = (middleware, filePath) => | ||
middleware.includes('') || |
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.
Ah, never mind. I think I figured it out by looking at the tests.
Summary
When static file moving is enabled, pre-rendered pages are moved to the CDN rather than being served from the origin with next/server. This causes a problem if the site uses middleware, as it does not run on pages served from the CDN. This PR checks any moved files to see if they match any middleware. If they do, it does not move them to the CDN and instead serves them from the origin. It also logs a warning about this.
Test plan
EXPERIMENTAL_MOVE_STATIC_PAGES
./middle
Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal
Fixes #802
Standard checks:
🧪 Once merged, make sure to update the version if needed and that it was published correctly.