Skip to content

Commit a1da6ed

Browse files
committed
make proxy loader handle API routes
1 parent 29375c8 commit a1da6ed

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ export default async function proxyLoader(this: LoaderThis<LoaderOptions>, userC
3333
// homepage), sub back in the root route
3434
.replace(/^$/, '/');
3535

36-
// TODO: For the moment we skip API routes. Those will need to be handled slightly differently because of the manual
37-
// wrapping we've already been having people do using `withSentry`.
38-
if (parameterizedRoute.startsWith('api')) {
39-
return userCode;
40-
}
41-
4236
// We don't want to wrap twice (or infinitely), so in the proxy we add this query string onto references to the
4337
// wrapped file, so that we know that it's already been processed. (Adding this query string is also necessary to
4438
// convince webpack that it's a different file than the one it's in the middle of loading now, so that the originals
@@ -47,7 +41,8 @@ export default async function proxyLoader(this: LoaderThis<LoaderOptions>, userC
4741
return userCode;
4842
}
4943

50-
const templatePath = path.resolve(__dirname, '../templates/proxyLoaderTemplate.js');
44+
const templateFile = parameterizedRoute.startsWith('/api') ? 'apiProxyLoaderTemplate.js' : 'proxyLoaderTemplate.js';
45+
const templatePath = path.resolve(__dirname, `../templates/${templateFile}`);
5146
let templateCode = fs.readFileSync(templatePath).toString();
5247
// Make sure the template is included when runing `webpack watch`
5348
this.addDependency(templatePath);

0 commit comments

Comments
 (0)