Skip to content

Commit c4bfc01

Browse files
committed
use excludeServerRoutes in the proxy loader for skipping files
1 parent 354fd4f commit c4bfc01

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/nextjs/src/config/loaders/proxyLoader.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { escapeStringForRegex, logger } from '@sentry/utils';
1+
import { escapeStringForRegex, logger, stringMatchesSomePattern } from '@sentry/utils';
22
import * as fs from 'fs';
33
import * as path from 'path';
44

@@ -8,6 +8,7 @@ import { LoaderThis } from './types';
88
type LoaderOptions = {
99
pagesDir: string;
1010
pageExtensionRegex: string;
11+
excludeServerRoutes: Array<RegExp | string>;
1112
};
1213

1314
/**
@@ -17,7 +18,11 @@ type LoaderOptions = {
1718
*/
1819
export default async function proxyLoader(this: LoaderThis<LoaderOptions>, userCode: string): Promise<string> {
1920
// We know one or the other will be defined, depending on the version of webpack being used
20-
const { pagesDir, pageExtensionRegex } = 'getOptions' in this ? this.getOptions() : this.query;
21+
const {
22+
pagesDir,
23+
pageExtensionRegex,
24+
excludeServerRoutes = [],
25+
} = 'getOptions' in this ? this.getOptions() : this.query;
2126

2227
// Get the parameterized route name from this page's filepath
2328
const parameterizedRoute = path
@@ -34,6 +39,11 @@ export default async function proxyLoader(this: LoaderThis<LoaderOptions>, userC
3439
// homepage), sub back in the root route
3540
.replace(/^$/, '/');
3641

42+
// Skip explicitly-ignored pages
43+
if (stringMatchesSomePattern(parameterizedRoute, excludeServerRoutes, true)) {
44+
return userCode;
45+
}
46+
3747
// We don't want to wrap twice (or infinitely), so in the proxy we add this query string onto references to the
3848
// wrapped file, so that we know that it's already been processed. (Adding this query string is also necessary to
3949
// convince webpack that it's a different file than the one it's in the middle of loading now, so that the originals

packages/nextjs/src/config/webpack.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ export function constructWebpackConfigFunction(
9191
use: [
9292
{
9393
loader: path.resolve(__dirname, 'loaders/proxyLoader.js'),
94-
options: { pagesDir, pageExtensionRegex },
94+
options: {
95+
pagesDir,
96+
pageExtensionRegex,
97+
excludeServerRoutes: userSentryOptions.excludeServerRoutes,
98+
},
9599
},
96100
],
97101
});

0 commit comments

Comments
 (0)