Comments (4)
Sure, feel free to pull request the documentation you feel would be appropriate:+1:
from serve-index.
I have a app that sits behind a reverse proxy so that http://server/appname serves data from an express app that is listening on http://localhost:4444/.
The following worked (make it the first express route)
let proxyAppPath = "/appname";
app.use(function (req, res, next) {
req.originalUrl = proxyAppPath + req.url;
next();
})
Note that if someone decides to change the reverse proxy URL to say http://server/BetterAppName, the directory listing will not longer work unless proxyAppPath
is updated. The reverse proxy does not provide information in the headers from which proxyAppPath
can be determined, so this seems to be about the best I can do aside from creating a custom template (discussed below).
I don't think this is a good solution - even if the proxy provided the needed header information, the links in a serve-index directory listing could break if the proxy software changes and different headers are used.
Given that adding an option to serve-index
of, say, absoluteDirPaths
which is by default true
and when false
uses var path = [];
as mentioned in #53 seems not simple *
based on the discussion, for documentation, I would suggest an example of how to get relative paths by creating a custom template as this seems to be the only robust solution. I suppose the template function would be essentially a copy of the existing template with a line or two modified.
*
Given that relative links in directory listings and responses of directory listings for URLs with and without a trailing slash work in apache by default, it can be done. It seems that apache sends a 301 when a URL is missing a trailing slash and the path associated with the URL maps to a file system directory. But implementing this would probably require substantial changes and tests.
from serve-index.
I don't think this is a good solution - even if the proxy provided the needed header information, the links in a serve-index directory listing could break if the proxy software changes and different headers are used.
The "x-original-url" is something you must manually setup in your proxy server. There are known solutions for both nginx & apache. As such, the manual header is an acceptable solution.
For example.
serve-index
configured with base path of "/tmp/files"- The request path is "/example/folder/"
- The proxy server sets x-original-url as "/example/folder"
- express application receives request at path "/folder"
serve-index
reads "/tmp/files/folder" and returns a template "mounted" on "/example" because it parsed that information from x-original-url
Now change the proxy location to "/passalong"
serve-index
is still configured with base path of "/tmp/files"- The request path is "/passalong/folder"
- The proxy server set x-original-url as "/passalong/folder"
- express application receives request at path "/folder"
serve-index
reads "/tmp/files/folder" and returns a template "mounted" on "/passalong" because it parsed that information from x-original-url
Note the only change was the proxy location. Everything else did not change.
from serve-index.
I agree that x-original-url
is a good option if you have control of the proxy server.
from serve-index.
Related Issues (20)
- Enable the use of custom filesystems HOT 30
- How to generate directory indices for all folders?
- Allow use of tables HOT 2
- Update debug https://snyk.io/vuln/npm:ms:20170412 HOT 1
- Example code doesn't work properly HOT 1
- Cannot stat `System Volume Information` sub dir on a root drive on Windows 10 HOT 1
- POST requests are rejected with 405 HOT 4
- Password protect a folder with HTTP Basic Authentication HOT 1
- code style: semicolons or no? HOT 6
- option to download files rather than view HOT 16
- How to handle fs.stat error on a file? HOT 4
- selecting file via a redirect goes to the wrong url HOT 2
- Badly encoded URLs are HTTP 500 HOT 2
- Failing test HOT 1
- add .npmignore HOT 4
- The `directory.html` template should be added in `locals` HOT 3
- Display content in existing HTML? HOT 7
- How to custom handle ForbiddenError: Forbidden with malicious path traversal characters HOT 1
- svg icon HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serve-index.