Closed vladimir-shilin closed 5 years ago
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
:memo: Please visit https://cla.developers.google.com/ to sign.
Once you've signed (or fixed any issues), please reply here (e.g. I signed it!
) and we'll verify it.
I signed it!
CLAs look good, thanks!
I've seen the opposite requests as well where dev workflow was supposed to override the locally available files. I.e. order matters. I wonder if we should deprecate serveOrigin
in favor of a smarter serveFolder
:
app.serveFolder('http://localhost', 'prefix');
app.serveFolder('www');
These would be matched in the specified order. Would that work for you?
Yes. That would be great.
Do you want to do it or should I?
I can try.
Sounds good! I was thinking of keeping serveOrigin
for backwards compat:
serveOrigin(origin) {
this.serveFolder(origin);
}
and then in the for (const [prefix, folders] of this.www_)
loop detect those that are origins and serve files respectively. We can assume that serving from the origin always succeeds.
I see the problem that search of file will stop at first folder which is url. I think we need make request in that case and check response code. Can I use some library for that or use node http
and https
libraries instead?
I thought your prefix
was sufficient to match deterministically. Could you paste your filsystem structure and which files you would like to serve over http for me to understand it better?
In my case I'll have index.html and app.js on http://locahost
and other files in filesystem by prefixes. For example app.serveFolder('http://locahost'); app.serveFolder('somefolder/images', 'images');
Even in this case request /images/1.jpg
will match prefix ''
and get 404 error.
This would do what you want though, right? (Order matters)
app.serveFolder('somefolder/images', 'images');
app.serveFolder('http://locahost');
Not exactly. At first app opens, then user choose folder with images.
Got it. Let me take it offline. You might need manual request interception to resolve this. I was planning on adding it anyways.
Thanks. Good luck!
I need to serve application from wwwOrigin in development mode, but app need to have access to filesystem. At first this code searches files by prefixes in filesystem, then tries to get it from wwwOrigin. Also there is fix which converts url to path for searching in filesystem with
decodeURIComponent
function.