jfhbrook / node-ecstatic

A static file server middleware that works with core http, express or on the CLI!
https://github.com/jfhbrook/node-ecstatic
MIT License
975 stars 194 forks source link

Serve file with default ext is same name dir cannot be shown #239

Open jonrimmer opened 5 years ago

jonrimmer commented 5 years ago

I was trying to use Ecstatic (via http-server) to serve Angular's ES2015 modules. This means serving with .js default extension. I had problems because they have some files named e.g. metadata.js that also have a corresponding directory with the same name. Attempting to import ./metadata resolves to the directory, but since there is no index.js inside it, and showDir is false, this results in a 404. In this case, I think Ecstatic should fall back to serving the document with the default extension, if one exists.

I.e the proposed logic would be this:

jfhbrook commented 5 years ago

This sounds like good stuff - I believe https://github.com/jfhbrook/node-ecstatic/blob/master/lib/ecstatic.js#L352-L371 is the code that would need to be refactored. A number of new tests would need to be written as well.

If someone wants to tackle this I would definitely take this!

jfhbrook commented 5 years ago

This issue is also likely relevant - in a similar location in the code and probably worth wrapping into the same PR: https://github.com/jfhbrook/node-ecstatic/issues/88