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

selecting file via a redirect goes to the wrong url #87

Closed
noscoot opened this issue Dec 19, 2018 · 2 comments
Closed

selecting file via a redirect goes to the wrong url #87

noscoot opened this issue Dec 19, 2018 · 2 comments
Assignees

Comments

@noscoot
Copy link

noscoot commented Dec 19, 2018

Hi
I'm new to serve-index, so maybe I'm doing something wrong or my set up is a little different.

When I select the file to download from the page listing, it goes to the wrong path with my redirect through nginx access.

Listing all the files works fine for my directly connecting node service
http://nodeserver:3077/reports/

and with niginx redirect to (http://foo/bar > http://nodeserver:3077)
http://foo/bar/reports/

This is my code for adding "reports" folder to my site.
app.use('/reports/', express.static('./reports/'), serveIndex('./reports/', {'icons': true}));

But if I select the file for download on the nginx version the path is:
http://foo/reports/report1.txt

It drops the "bar", it should be
http://foo/bar/reports/report1.txt

It works fine if I connect directly to the node service site

I found if I change path variable in function createHtmlFileList
from
var path = dir.split('/').map(function (c) { return encodeURIComponent(c); });
to
var path = [];

it works for my two cases.

Is there something I can do with the set up of serve-index to make it work?

thanks
Scott

@dougwilson
Copy link
Contributor

Hi Scott, you just need to have req.originalUrl set to the original one prior to the nginx rewrite for this (and other express middlewares) to generate proper URLs. A full explanation and example can be found in a previous response here: #53 (comment)

Let me know if you're still having an issue, though I am not familiar with nginx to help with any nginx specific questions.

@noscoot
Copy link
Author

noscoot commented Dec 19, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants