-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(nextjs): Add excludeServerRoutes
config option
#6207
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
Merged
lobsterkatie
merged 7 commits into
master
from
kmclb-nextjs-add-excludeServerPages-option
Nov 15, 2022
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3bf486c
add `excludeServerRoutes` option
lobsterkatie 75c0035
use `excludeServerRoutes` in the proxy loader for skipping files
lobsterkatie cbdf3a1
prevent `Sentry.init()` code from being injected into excluded routes
lobsterkatie f962329
prevent webpack plugin from injecting release file into excluded routes
lobsterkatie 192e8da
log when a route has been excluded
lobsterkatie e3e30f6
add integration tests
lobsterkatie a92e32f
add unit test for `excludeServerRoutes`
lobsterkatie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
6 changes: 6 additions & 0 deletions
6
packages/nextjs/test/integration/pages/api/excludedEndpoints/excludedWithRegExp.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// This file will test the `excludeServerRoutes` option when a route is provided as a RegExp. | ||
const handler = async (): Promise<void> => { | ||
throw new Error('API Error'); | ||
}; | ||
|
||
export default handler; |
6 changes: 6 additions & 0 deletions
6
packages/nextjs/test/integration/pages/api/excludedEndpoints/excludedWithString.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// This file will test the `excludeServerRoutes` option when a route is provided as a string. | ||
const handler = async (): Promise<void> => { | ||
throw new Error('API Error'); | ||
}; | ||
|
||
export default handler; |
67 changes: 67 additions & 0 deletions
67
packages/nextjs/test/integration/test/server/excludedApiEndpoints.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const assert = require('assert'); | ||
|
||
const { sleep } = require('../utils/common'); | ||
const { getAsync, interceptEventRequest, interceptTracingRequest } = require('../utils/server'); | ||
|
||
module.exports = async ({ url: urlBase, argv }) => { | ||
const regExpUrl = `${urlBase}/api/excludedEndpoints/excludedWithRegExp`; | ||
const stringUrl = `${urlBase}/api/excludedEndpoints/excludedWithString`; | ||
|
||
const capturedRegExpErrorRequest = interceptEventRequest( | ||
{ | ||
exception: { | ||
values: [ | ||
{ | ||
type: 'Error', | ||
value: 'API Error', | ||
}, | ||
], | ||
}, | ||
tags: { | ||
runtime: 'node', | ||
}, | ||
request: { | ||
url: regExpUrl, | ||
method: 'GET', | ||
}, | ||
transaction: 'GET /api/excludedEndpoints/excludedWithRegExp', | ||
}, | ||
argv, | ||
'excluded API endpoint via RegExp', | ||
); | ||
|
||
const capturedStringErrorRequest = interceptEventRequest( | ||
{ | ||
exception: { | ||
values: [ | ||
{ | ||
type: 'Error', | ||
value: 'API Error', | ||
}, | ||
], | ||
}, | ||
tags: { | ||
runtime: 'node', | ||
}, | ||
request: { | ||
url: regExpUrl, | ||
method: 'GET', | ||
}, | ||
transaction: 'GET /api/excludedEndpoints/excludedWithString', | ||
}, | ||
argv, | ||
'excluded API endpoint via String', | ||
); | ||
|
||
await Promise.all([getAsync(regExpUrl), getAsync(stringUrl)]); | ||
await sleep(250); | ||
|
||
assert.ok( | ||
!capturedRegExpErrorRequest.isDone(), | ||
'Did intercept error request even though route should be excluded (RegExp)', | ||
); | ||
assert.ok( | ||
!capturedStringErrorRequest.isDone(), | ||
'Did intercept error request even though route should be excluded (String)', | ||
); | ||
}; |
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.
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.
m: Just something we should maybe think about: I am wondering if we should have users include
"pages/"
in the strings/regexes they provide here just to future-proof us against Next.js 13'sapp/
folder. However, the more I think about it it shouldn't matter, as the routes in theapp/
folder will also just be routes like we have in the pages folder and I believe they can't collide - so we're probably good here.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 a good question, but I think you're right, a route is a route and you can't have two with the same route path. I also think that it's better that we abstract away the underlying file structure. That way, as users do move their routes from
pages/
toapp/
, they won't have to come and update this setting.