-
-
Notifications
You must be signed in to change notification settings - Fork 463
Bug - API Routes do not handle query parameters. #123
Comments
@danielcondemarin - any chance this could be something within next-aws-lambda? I see there's some query string manipulation in compatLayer.js
|
I encountered this yesterday as well, there's actually a bug with nextjs which incorrectly matches on the last path segment. I'm working on a fix here https://github.com/Deadleg/next.js/commit/5bdcd698bd6aaf1ac1e0d53fd50b94636e17c458 but the long and short of it there is a regex in Note that if you run You can apply the below patch which works around the issue, but breaks custom paths. I think if nextjs is fixed then we don't need to do anything in this project. diff
diff --git a/packages/next-aws-lambda/lib/compatLayer.js b/packages/next-aws-lambda/lib/compatLayer.js
index 7d19fa6..213c7aa 100644
--- a/packages/next-aws-lambda/lib/compatLayer.js
+++ b/packages/next-aws-lambda/lib/compatLayer.js
@@ -10,8 +10,9 @@ const reqResMapper = (event, callback) => {
multiValueHeaders: {}
};
+
const req = new Stream.Readable();
- req.url = (event.requestContext.path || event.path || "").replace(
+ req.url = (event.path || "").replace(
new RegExp("^/" + event.requestContext.stage),
""
);
@@ -22,15 +23,15 @@ const reqResMapper = (event, callback) => {
qs += queryString.stringify(event.multiValueQueryStringParameters);
}
- if (event.pathParameters) {
- const pathParametersQs = queryString.stringify(event.pathParameters);
-
- if (qs.length > 0) {
- qs += `&${pathParametersQs}`;
- } else {
- qs += pathParametersQs;
- }
- }
+// if (event.pathParameters) {
+// const pathParametersQs = queryString.stringify(event.pathParameters);
+//
+// if (qs.length > 0) {
+// qs += `&${pathParametersQs}`;
+// } else {
+// qs += pathParametersQs;
+// }
+// }
const hasQueryString = qs.length > 0;
|
You can work around it by not using a dynamic file name e.g. change |
Ignore the work around, need to use the patch. Created pull request here vercel/next.js#8386 |
Amazing detail @Deadleg - thanks for raising that PR! |
Next.js 9.0.4 has just been released, from my testing APIs are working correctly. |
I've updated to Next 9.0.4 and I keep getting a 502 from all endpoints. This one is from my index page at
|
That doesn't look right, |
It is...
|
Looks like a new feature in ES10 called optional catch binding is causing the syntax error. Upgrading node may fix the issue, I'm building and running with the latest available version on Lambda. |
Good catch! I was running Node 8 in AWS so I've bumped it to Node 10 in my serverless.yml and I've got a website again. :)
|
The merge of #99 and #117 has given us support for API Routes in NextJS 🎉
However, I have noticed a bug when sending query parameters.
Here is a copy of my endpoint (apologies for the poor naming conventions but this is a WIP). It simply takes a relative path request and proxies to the fully qualified path on the server. Whether or not this is a best practice at this point is 🤷♂
And I call it with this endpoint:
When I run this locally, the NextJS convention is that
path
resolves toclassic-api
endpoint
resolves tonews-listing.asp
queryString
resolves to?catId=26&skip=9&take=8
When I deploy this to AWS, API Gateway resolves to this
path
resolves toclassic-api
endpoint
resolves tonews-listing.asp?catId=26&skip=9&take=8&path=classic-api&endpoint=news-listing.asp
queryString
resolves to?catId=26&skip=9&take=8
The problem seems to be how
endpoint
is being resolved in AWS.Instead of forwarding on my request to
it instead forwards it on to
If anyone has any ideas of where to get started it would be much appreciated. Ultimately I want the plugin to behave in the same way as NextJS.
The text was updated successfully, but these errors were encountered: