Skip to content
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

Pouchdb Fauxton path mismatch via Reverse Proxy #431

Open
cefn opened this issue Mar 7, 2020 · 0 comments
Open

Pouchdb Fauxton path mismatch via Reverse Proxy #431

cefn opened this issue Mar 7, 2020 · 0 comments

Comments

@cefn
Copy link

@cefn cefn commented Mar 7, 2020

Hi all and thanks for your work on Pouchdb! It was a really exciting discovery for me, and I am hoping to do great things!

Unfortunately, the bundled version of Fauxton still seems to suffer from apache/couchdb-fauxton#944 meaning it cannot function when the express app is routed via a Reverse Proxy (e.g. Amazon API Gateway). Otherwise it would be perfect for my case.

Because of the incorrect resource paths from that bug, only the left bar of Fauxton appears, and none of the controls work. My pouchdb NodeJS app works when locally hosted, but not when mapped to the path /dev/ through a reverse proxy.

I would be glad of any pointers how to solve this issue the right way with the fewest hacks. See the Chrome inspector screenshot below for the mismatched URLs.
image

Fauxton's logic incorrectly calculates the db resource path at / and authentication resource path at /_session causing the failures shown above. The logic doesn't take account of the mount point /dev/. Fauxton should in fact have retrieved the db resource from /dev/ and hit /dev/_session for authentication.

This is possibly because express itself thinks the root path is /, before the reverse proxy gets its hands on it and maps it to /dev/. The URL the pouchdb-server can see(through express) cannot be used by an external HTTP client.

I am happy to make the URL resource path explicit in my code if there is some way to do so. I have no choice but to use a reverse proxy for my case without a LOT of extra engineering.

FIXES OUT THERE?

Some work on the authentication plugin looks like it might have addressed the issue with _session being routed incorrectly.
pouchdb-community/pouchdb-authentication#215

However, overall mounting Pouchdb Fauxton anywhere except /_utils/ seems like an unsolved issue since the last comment on #260 17 Oct 2018

Is this because the fix hasn't been bundled through pouchdb-fauxton yet? Or doesn't the fix work in my case (where a reverse proxy is changing the mount point from the resource path express can see).

Alternatively perhaps there's a trivial way to work around the issue meaning noone has had a major reason to work on it. Is following #183 (comment) the right way forward?

I recall a comment about possibly adding a config property that can be set to tell pouchdb what its external root URL is, but I can't find that property.

Luckily the database endpoints themselves seem to be fine. However, key endpoints for the Fauxton SPA have incorrectly mapped URLs .

BACKGROUND - MY USE CASE

I encountered the issue when mounting pouchdb-server via aws-serverless-express on an AWS Lambda. Spent a long time trying to debug what I assumed was a Lambda event-translation, CORS or Mime Type issue. Finally found AWS API Gateway was mounting handlers via a reverse-proxy at servername.awsthingy.com/dev/.

@cefn cefn changed the title Pouchdb Fauxton path mismatch when Reverse Proxied Pouchdb Fauxton path mismatch via Reverse Proxy Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.