-
Notifications
You must be signed in to change notification settings - Fork 166
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
Correct path for non-custom endpoints #42
Conversation
event.requestContenx.path includes it and is correct for all cases I believe.
Thanks for this! |
Hey, @bsdkurt I have to revert this, it doesn't seem to work as expected. Now that I think about it, I don't think we want the path to contain the stage. |
@dougmoscrop What use case broke? |
@dougmoscrop Ok I see the bug reports. There does seem to be two use cases that would need to adjust for this change:
I do think this is the correct path to expose since for non-custom domain endpoints what is exposed now is incorrect (e.g. #35) and also would require the developer to make changes to the routing to account for the additional path segment if the same code is migrated to a custom domain with a basepath. Due to the need for adjustments for the two cases above, perhaps this change is better suited for a 1.6 or 2.0 release with upgrade instructions for the two cases? |
I'm not sure if it's correct to expose it. The application routing logic won't match when the stage is exposed. You write app routers as "relative" to some assumed baseUrl (which is empty). |
Let's take three cases for a GET at the root where lambda attaches:
I believe express expects to know the full path as can be seen in #35. That's why I think |
If you app.use(/foo) are you saying express understands /dev/foo? |
(baseUrl is a separate concept) I think we want to set baseUrl to rc.path.replace(event.path, '') |
Yeah bunch of people had to mount their app under the stage name which isn't ideal |
@bsdkurt Did you try my PR #36?
If you have a use case that is missing and breaks then I'm sure that between the three of us, we can square the wheel. |
It has been my intention for far too long now to create a sample project that demonstrates the different configurations but I have to admit that it still remains on my todo list. And I'm off on holiday tomorrow morning so it will have to wait a while longer. |
If you could, add them to the integration test. I run it before publish.
…On Wed, Mar 28, 2018, 5:33 PM XuluWarrior ***@***.***> wrote:
It has been my intention for far too long now to create a sample project
that demonstrates the different configurations but I have to admit that it
still remains on my todo list. And I'm off on holiday tomorrow morning so
it will have to wait a while longer.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#42 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAjzFOj6uDNUKi06jx3kF9_MW9_sDwdDks5tjAG5gaJpZM4S6ili>
.
|
@dougmoscrop Sorry for disrupting the userbase with the PR. I think I'm not doing a very good job explaining why I think the change is correct. Suppose we were running express or koa in node (not with AWS API GW). Is there a scenario where the user types this url in the browser If it is correct to say that express and koa expect the request.url to include /pathsegment1/ from the listener always, then I would make a case that since AWS forces the stage on its endpoints, that it should be there for express or koa to see. If I was planning on using AWS endpoints I would have the following setup: const router = express.Router();
router.get('/', rootget);
...
app.use('/' + process.env.STAGE_NAME, router); For custom domains with basepaths, I would use the same solution but use process.env.BASE_PATH. @XuluWarrior I didn't try #36 because I didn't think it was the correct fix. baseUrl is an express request object extension, koa doesn't support baseUrl on the request object. baseUrl is also set by express route.js. I thought from code inspection that it may be replaced with express's idea of what baseUrl should be, although I didn't test that to see if I can break it. |
I certainly think there is a gap here! I'm just not sure where it is or what the best fix it. API Gateway is mounting the application in a non-transparent way only in certain scenarios. |
I've finally created a demo repository (https://github.com/XuluWarrior/serverless-http-tests) that demonstrates the issue as I understand it. It has three branches master The issue that started me looking at this is that when you visit This is because express.static depends on baseUrl to determine the full redirect url. https://api.xuluwarrior.org/serverless-http-tests/static redirects as expected set-baseurl koa However, the koa code sets I have added a hacky middleware function that does the copy. I have done this not to suggest that it is the correct solution but just to show possibilities. The koa server is live at |
thanks! need to think about what the best course of action is so not to upend all libraries for the sake of one, or collide with fields that are used differently between libraries. |
Thought: One way to figure this out might be to check if the Host: header contains the execute-api.blahblah and then we know we should add the stage name to the originalUrl/url. |
Non-custom domain endpoints (e.g. https://xyz.execute-api.region.amazonws.com/{stage}) strip off {stage} in event.path, but event.requestContext.path is correct for all cases I believe. Also should fix #35.