Munter/fusile

Browser requests to files in mounted filesystem not completing

Munawwar opened this issue · 4 comments

The problem: When using mounted directory as static file root with expressjs, browser requests to files doesn't seem to complete. Tested on Chrome.
An example is attached - test-fusile.zip. To run the exmaple, first do npm install, then node_modules/fusile/bin/fusile-bin.js http-src/ http-dev/. Then on a second terminal run node server.js.


I believe the problem is caused by a wrong Content-Length HTTP header size, which in turn causes browser to wait forever. Expressjs sets Content-Length to size of file, and fusile seems to return the wrong file size due to this line -> https://github.com/Munter/fusile/blob/master/lib/index.js#L176.

My proposed solution to this:
Step 1: If a transpile-able file is being read or stats'ed, compile it and cache the size and timestamp. From what I see the OS file manager doesn't recursively stats the mounted directory. It only goes through the top/first level files/directories.
Step 2: If any of those file changes, recompile that file and update cache.
Step 3: When exiting fusile, save the cache to a .fusile.json file, which will be reloaded when fusile is started the next time (Check for file updates there, since cache could be outdated).
This still makes fusile better than a 'clone directory + file watchers' solution at least.

I think we're going to switch it back to compile on stat. With an on-disk cache so it can persist across instances. But this time around I need to be sure I can write tests that actually cover more things. I'll meet with @papandreou to talk that through

If you need any help or don't have time to complete this, ping me. I guess I am more in need of this issue being resolved than yourself :)

We just had a bit of a code sprint and wrote a file system backed cache with much of the same basic plumbing than fusile, just better thought through. With a file system backed cache I should be able to rewrite fusile to compile on stat without to much of a start up penalty. That should fix the problem of wrongly reported file lengths.

https://github.com/assetgraph/skrin